Created
October 30, 2019 03:17
-
-
Save wtfaremyinitials/c76e9600441e8a73a395d3115042c6f3 to your computer and use it in GitHub Desktop.
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
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