Web / ReactJS Interview questions
What are React fragments?
React fragments are a common pattern in React for a component to return multiple elements. Fragments let you group a list of children without having to add extra nodes to the DOM.
render() { return ( <React.Fragment> <h1>React Fragment example</h1> <ComponentA /> <ComponentB /> <ComponentC /> </React.Fragment> ); }
There is also a shorter syntax you can use for declaring fragments. It looks like empty tags <> </>:
render() { return ( <> <ComponentA /> <ComponentB /> </> ); }
More Related questions...