React fragments let you group a list of children elements without adding extra nodes to the DOM. This helps keep your HTML clean and avoids unnecessary wrappers that might affect styling or layout.
div
or other wrapper elements.You can use fragments in two ways:
<React.Fragment> ... </React.Fragment>
<> ... </>
function Table() { return ( <React.Fragment> <tr> <td>Row 1, Cell 1</td> <td>Row 1, Cell 2</td> </tr> <tr> <td>Row 2, Cell 1</td> <td>Row 2, Cell 2</td> </tr> </React.Fragment> ); }
Or using short syntax:
function List() { return ( <> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> </> ); }
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!