-
-
Save brigand/94c09476676a70e78e33ca84f0cc8ad3 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
const h = (selector, props, ...children) => { | |
if (typeof selector !== 'string') { | |
return React.createElement(selector, props, ...children); | |
} | |
const classNames = []; | |
const tagName = selector.replace(/\.([^.]+)/g, (match, className) => { | |
classNames.push(className); | |
return ''; | |
}); | |
let newProps = props; | |
if (props && props.className) { | |
classNames.push(props.className); | |
} | |
if (classNames.length) { | |
if (!newProps) newProps = {}; | |
newProps = Object.assign({}, props, {className: classNames.join(' ')}); | |
} | |
return React.createElement(tagName, newProps, ...children); | |
}; | |
module.exports = h; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment