Last active
April 22, 2016 11:50
-
-
Save sebjwallace/ee4897b516e309e6f2eb1edd94d3df68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Hello(name){ | |
return ["div", null, | |
["b", null, "Hello "], | |
["i", null, name] | |
]; | |
} | |
function prerender(root){ | |
for(var i in root) | |
if(Array.isArray(root[i])) | |
root[i] = prerender(root[i]) | |
return React.createElement.apply(this, root) | |
} | |
ReactDOM.render( | |
prerender(Hello("World")), | |
document.getElementById('container') | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Hello(name,key){ | |
// React wants key props for itertators | |
return ["p", {key: key}, | |
["b", null, "Hello "], | |
["i", null, name] | |
]; | |
} | |
function HelloAll(names){ | |
var allNames = names.map(function(name,i){ | |
return Hello(name,i) | |
}) | |
return ["div", null, allNames] | |
} | |
function prerender(root){ | |
for(var i in root) | |
if(Array.isArray(root[i])) | |
root[i] = prerender(root[i]) | |
if(typeof root[0] == 'string') | |
return React.createElement.apply(this, root) | |
else return root | |
} | |
var names = ["John", "Amy", "Paul", "Kay"] | |
ReactDOM.render( | |
prerender(HelloAll(names)), | |
document.getElementById('container') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment