What are fragments?
It’s common pattern in React which is used for a component to return multiple elements. Fragments let you group a list of children without adding extra nodes to the DOM.
1 2 3 4 5 6 7 8 9 | render() { return ( <React.Fragment> <ChildA /> <ChildB /> <ChildC /> </React.Fragment> ) } |
There is also a shorter syntax, but it’s not supported in many tools:
1 2 3 4 5 6 7 8 9 | render() { return ( <> <ChildA /> <ChildB /> <ChildC /> </> ) } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.