Because JSX compiles into a single JavaScript function call (React.createElement), every React component must return a single root element. In earlier versions of React, developers routinely wrapped sibling elements in an extra <div>. This created "div soup"—cluttered DOM trees that broke CSS Grid, Flexbox, and table layouts (such as <td> elements inside a <tr>).
React Fragments allow you to group multiple child elements without producing any physical node in the browser DOM:
import React from 'react';
// Short Syntax: <>...</>
function TableColumns() {
return (
<>
<td>Roll #101</td>
<td>Aarav Patel</td>
<td>BCA 2nd Year</td>
</>
);
}
// Keyed Fragment inside Array.map()
function GlossaryList({ items }) {
return (
<dl>
{items.map(item => (
// Must use explicit <React.Fragment key={...}> when keys are needed!
<React.Fragment key={item.id}>
<dt><b>{item.term}</b></dt>
<dd>{item.definition}</dd>
</React.Fragment>
))}
</dl>
);
}
Wrapped around your application in main.jsx, <React.StrictMode> acts as a silent compiler auditor in development:
componentWillMount).Now let us step into high-performance optimizations in React useMemo & useCallback.
Accelerate your React mastery by studying these tightly connected core tutorials:
Why React requires a single root element.
Rendering list items without unwanted wrapper divs.
Preventing markup clutter in CSS Grid and Flex parents.