React.Fragment lets you wrap multiple elements without creating extra
or container tags in the DOM.π― Why use React.Fragment?
β’ Keeps your DOM clean (no unnecessary wrapper elements)
β’ Improves performance by avoiding extra nodes
β’ Helps when returning multiple elements from a component
π§ Example:
import React from "react"; function List() { return ( <React.Fragment> <li>Apple</li> <li>Banana</li> <li>Orange</li> </React.Fragment> ); } π‘ Short syntax:
<> <li>Apple</li> <li>Banana</li> <li>Orange</li> </> π Key points:
β’ Use or <>
β’ No extra clutter in your HTML
β’ Useful in lists, table rows, and any multi-element return
React.Fragment is a small but powerful tool for writing clean, minimal DOM structures.
Top comments (1)
Good π