-
-
Save johnholdun/d3e2a5f0c123df51e117cd5ae42e7e24 to your computer and use it in GitHub Desktop.
who needs jsx?
This file contains hidden or 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
function h(tag, props = {}, children = null) { | |
if (arguments.length === 2 && props && (typeof props !== 'object' || Array.isArray(props))) { | |
children = props | |
props = {} | |
} | |
const inner = children ? [].concat(children).join('') : '' | |
if (!tag) { | |
return inner | |
} | |
const htmlProps = Object.entries(props).map(([k, v]) => `${k}="${v}"`) | |
const start = `<${[tag].concat(htmlProps).join(' ')}>` | |
const end = `</${tag}>` | |
return [start, inner, end].join('') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment