Skip to content

Instantly share code, notes, and snippets.

@rajeshpillai
Created December 17, 2018 11:27
Show Gist options
  • Save rajeshpillai/2529076dd958d75f77480e8909f01ebf to your computer and use it in GitHub Desktop.
Save rajeshpillai/2529076dd958d75f77480e8909f01ebf to your computer and use it in GitHub Desktop.
createElement - Version - 1
const TinyReact = (function () {
function createElement(type, attributes = {}, ...children) {
const childElements = [].concat(...children).map(
child =>
child instanceof Object
? child
: createElement("text", {
textContent: child
})
);
return {
type,
children: childElements,
props: Object.assign({ children: childElements }, attributes)
}
}
return {
createElement
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment