Last active
July 14, 2018 08:13
-
-
Save frankfaustino/acfe13506e0d0d395d55cd9225497c77 to your computer and use it in GitHub Desktop.
React.html
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
<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