React 16.2 adds improved support for Fragments . More information can be found on the React blog here.
We are all familiar with the following code:
render() { return ( // Extraneous div element :( <div> Some text. <h2>A heading</h2> More text. <h2>Another heading</h2> Even more text. </div> ); }
Yes, we need a div container, but that is not that important.
In React 16.2, we can do this to avoid the surrounding div container:
render() { return ( <Fragment> Some text. <h2>A heading</h2> More text. <h2>Another heading</h2> Even more text. </Fragment> ); }
In any case, we still need the container element to surround the inner elements.
My question is: why use Fragment preferable? Does this help in performance? If so, why? I would like to see a little.
reactjs
Max Millington Dec 11 '17 at 21:41 2017-12-11 21:41
source share