Skip to content

Instantly share code, notes, and snippets.

@frankfaustino
Last active July 14, 2018 08:13
Show Gist options
  • Save frankfaustino/acfe13506e0d0d395d55cd9225497c77 to your computer and use it in GitHub Desktop.
Save frankfaustino/acfe13506e0d0d395d55cd9225497c77 to your computer and use it in GitHub Desktop.
React.html
<html>
<body>
<div id="root"></div>
</body>
<script>
const rootEl = document.getElementById('root')
function createElement(type, props, ...children) {
const element = document.createElement(type)
Object.entries(props).forEach(([key, value]) => {
element.setAttribute(key, value)
});
(props.children || children).forEach(child => {
if (typeof child === 'string') {
element.appendChild(document.createTextNode(child))
} else {
element.appendChild(child)
}
})
return element
}
const spanElement = createElement('span', {}, 'SPAN!')
const element = createElement('h1', { id: 'header', children: ['Hey there', spanElement] })
rootEl.appendChild(element)
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment