3 ms·
When I'm not using JSX, I often do something like this const define = (componentDefinition) => (props, ...children) => isReactNode(props) ? React.createEle
by kybernetikos 6y ago
When I'm not using JSX, I often do something like this
const define = (componentDefinition) => (props, ...children) => isReactNode(props) ? React.createElement(componentDefinition, {}, props, ...children) : React.createElement(componentDefinition, props, ...children);
const elements = new Proxy({}, {get: (target, tagName, _) => define(tagName)});
// ...
const {div, h1, button, input} = elements;
But although I really disliked JSX at first, once I tried it a little, I realised that it's about making the code describe what you want rather than how to get it. That mind set shift is actually valuable, even if underneath it's still turning into function calls.