Created
September 8, 2018 07:46
-
-
Save GeorgianStan/0c2c93806a62f73c0aef09bee581331e to your computer and use it in GitHub Desktop.
React - Vanilla JS
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
// where the magic happens | |
function createElement(type, props, text) { | |
const elem = document.createElement(type); | |
Object.keys(props).forEach(prop => elem[prop] = props[prop] ); | |
const textNode = document.createTextNode(text); | |
elem.appendChild(textNode); | |
return elem | |
} | |
// h1 and p blueprints | |
const h1 = (...args) => createElement(`h1`, ...args); | |
const p = (...args) => createElement(`p`, ...args); | |
// make magic | |
document.body.appendChild( | |
h1( | |
{ className: `myClass` }, | |
`Magic`, | |
) | |
); | |
document.body.appendChild( | |
p( | |
{ id: `myId` }, | |
`From Vanilla JS`, | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment