Fragments
A fragment is a wrapper that groups tags without adding a new element. It lets a return statement hold more than one tag.
Two tags, no div
The fragment groups a heading and a paragraph.
return (
<>
<h1>Welcome</h1>
<p>React is ready.</p>
</>
)Example
export default function App() {
return (
<>
<h1>Welcome</h1>
<p>React is ready.</p>
</>
)
}Key points
- A fragment opens with empty angle brackets and closes the same way.
- The fragment itself adds no div or tag to the page.
- The tags inside the fragment still show on the page.
- Fragments keep the page markup clean when no box is needed.
In this example, App returns a fragment. The fragment holds a heading and a paragraph. The fragment adds no tag of its own. The page shows the heading and the paragraph side by side.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
What does a fragment add to the page?