Skip to content

Instantly share code, notes, and snippets.

@GeorgianStan
Created September 8, 2018 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GeorgianStan/0c2c93806a62f73c0aef09bee581331e to your computer and use it in GitHub Desktop.
Save GeorgianStan/0c2c93806a62f73c0aef09bee581331e to your computer and use it in GitHub Desktop.
React - Vanilla JS
// 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