Skip to content

Instantly share code, notes, and snippets.

@wtfaremyinitials
Created October 30, 2019 03:17
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 wtfaremyinitials/c76e9600441e8a73a395d3115042c6f3 to your computer and use it in GitHub Desktop.
Save wtfaremyinitials/c76e9600441e8a73a395d3115042c6f3 to your computer and use it in GitHub Desktop.
import React from 'react'
import hyperx from 'hyperx'
export const h = function hyperz() {
let scope = this
if (!Array.isArray(arguments[0])) {
let newScope = arguments[0]
return hyperz.bind(Object.assign({}, scope, newScope))
}
// NOTE: children arg should really be ...children, but hyperx is buggy and
// returns an array rather than spreading JSX children
function createElement(component, props, children = []) {
// NOTE: this also shouldn't be here, but hyperx likes to create useless
// whitespace children
children = children.filter(c => typeof c != 'string' || c.trim() != '')
if (scope[component]) component = scope[component]
return React.createElement(component, props, ...children)
}
return hyperx(createElement).apply(null, arguments)
}.bind({})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment