Skip to content

Instantly share code, notes, and snippets.

@brigand brigand/.js Secret
Created Apr 25, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.