Skip to content

Instantly share code, notes, and snippets.

@sebjwallace
Last active April 22, 2016 11:50
Show Gist options
  • Save sebjwallace/ee4897b516e309e6f2eb1edd94d3df68 to your computer and use it in GitHub Desktop.
Save sebjwallace/ee4897b516e309e6f2eb1edd94d3df68 to your computer and use it in GitHub Desktop.
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')
);
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