3 ms·
Several people had already noted [0] that you could implement equivalent behavior by using a component that simply returns its own children: const Fragment
by acemarke 9y ago
Several people had already noted [0] that you could implement equivalent behavior by using a component that simply returns its own children:
const Fragment = ({children}) => children;
// later
return <Fragment><Component1 /><Component2 /></Fragment>;
Nice to see this added as both a built-in component type and a useful syntax extension. (Now if they'd just modify JSX syntax so that we can pass props by matching local variable names similar to how ES6 object literals work, like `<SomeComponent a b c />`, rather than having that become a defaulted-true boolean, I'd be happy :) )
[0] https://medium.com/@gajus/using-react-v16-to-create-self-destructing-components-de8e4eb61d0f https://medium.com/@gajus/using-react-v16-to-create-self-des...
- danabramov 9y agoTo be pedantic, it's not 100% equivalent. You can find the nitty-gritty details about the (intentional) differences here: https://github.com/facebook/react/pull/10783 https://github.com/facebook/react/pull/10783. We did mention the author of react-aux in the blog post though :-) >Thanks to Gajus Kuizinas and other contributors who prototyped the Fragment component in open source.
- girvo 9y agoThat works in ReasonML :)