DEV Community

Aman Kureshi
Aman Kureshi

Posted on

🧩 React.Fragment β€” Group Elements Without Adding Extra DOM Nodes

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)

Collapse
 
maheboobbhai_kureshi_9722 profile image
maheboobbhai kureshi

Good πŸ‘