Skip to content

Instantly share code, notes, and snippets.

@johnholdun
Created January 13, 2021 16:31
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 johnholdun/d3e2a5f0c123df51e117cd5ae42e7e24 to your computer and use it in GitHub Desktop.
Save johnholdun/d3e2a5f0c123df51e117cd5ae42e7e24 to your computer and use it in GitHub Desktop.
who needs jsx?
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