4 ms·
It doesn’t necessarily have the same benefits in React, but folks ought to consider using components for control flow, like SolidJS does[1]. 1: https://www.sol
by eyelidlessness 5y ago
It doesn’t necessarily have the same benefits in React, but folks ought to consider using components for control flow, like SolidJS does[1].
1: https://www.solidjs.com/docs/latest/api#control-flow https://www.solidjs.com/docs/latest/api#control-flow
- Eric_WVGG 5y agoThat's pretty slick.
- dimgl 5y agoFunnily enough, this has existed in React through a Babel plugin. I'm not sure why this hasn't really caught on. https://github.com/AlexGilleran/jsx-control-statements https://github.com/AlexGilleran/jsx-control-statements
- eyelidlessness 5y agoI’ve encountered that, and kind of don’t understand why you’d need a Babel plugin. They’re trivial components to implement in regular JSX.
- dimgl 5y agoThat's what I was thinking too!
- latchkey 5y agoSome people consider this added complexity? https://news.ycombinator.com/item?id=30509806 https://news.ycombinator.com/item?id=30509806
- eyelidlessness 5y agoI mean, sure. But compilers often impose complexity as a trade off for performance or other benefits.
- tdumitrescu 5y agoControl-flow components like "<For>"... because you couldn't stand just writing "for" or "if" like a caveman and had to invent a custom DSL for it.
- eyelidlessness 5y agoSolid actually uses them for static analysis which ~isn’t otherwise possible in JSX, which has to be an expression. It would be great if for/if were expressions in JS, but they’re not.
- kipple 5y agoAgreed. I particularly like the look of their `<Switch>/<Match>` component[1]: <Switch fallback={<div>Not Found</div>}> <Match when={state.route === "home"}> <Home /> </Match> <Match when={state.route === "settings"}> <Settings /> </Match> </Switch> Which doesn't seem to have an analog in the React babel-plugin[2] or standalone lib[3] [1] https://www.solidjs.com/docs/latest/api#%3Cswitch%3E%2F%3Cmatch%3E https://www.solidjs.com/docs/latest/api#%3Cswitch%3E%2F%3Cma... [2] https://github.com/AlexGilleran/jsx-control-statements https://github.com/AlexGilleran/jsx-control-statements [3] https://github.com/samuelneff/react-control-flow https://github.com/samuelneff/react-control-flow
- 14u2c 5y agoYou could very easily implement that pattern yourself in a react app as a few HoCs. So far I think the react project has done a pretty decent job at limiting the surface area of the API. This seems a bit high level.