Fragment - ( - ... - ) - React
Fragment - ( - ... - ) - React
</>) – React
v19
<Fragment> (<>...</>)
<Fragment> , often used via <>...</> syntax, lets you group
elements without a wrapper node.
<>
<OneChild />
<AnotherChild />
</>
Reference
<Fragment>
Usage
Reference
<Fragment>
https://react.dev/reference/react/Fragment 1/7
20/02/2025, 09:02 <Fragment> (<>...</>) – React
Props
Caveats
If you want to pass key to a Fragment, you can’t use the <>...</>
syntax. You have to explicitly import Fragment from 'react' and render
<Fragment key={yourKey}>...</Fragment> .
React does not reset state when you go from rendering <><Child /></>
to [<Child />] or back, or when you go from rendering <><Child /></>
to <Child /> and back. This only works a single level deep: for example,
going from <><><Child /></></> to <Child /> resets the state. See the
precise semantics here.
Usage
function Post() {
return (
<>
<PostTitle />
<PostBody />
</>
);
}
https://react.dev/reference/react/Fragment 2/7
20/02/2025, 09:02 <Fragment> (<>...</>) – React
Show more
https://react.dev/reference/react/Fragment 3/7
20/02/2025, 09:02 <Fragment> (<>...</>) – React
DEEP DIVE
Show Details
Like any other element, you can assign Fragment elements to variables, pass
them as props, and so on:
function CloseDialog() {
const buttons = (
<>
<OKButton />
<CancelButton />
</>
);
return (
<AlertDialog buttons={buttons}>
Are you sure you want to leave this page?
</AlertDialog>
);
}
https://react.dev/reference/react/Fragment 4/7
20/02/2025, 09:02 <Fragment> (<>...</>) – React
<>
From
<DatePicker date={start} />
to
<DatePicker date={end} />
</>
);
}
function Blog() {
return posts.map(post =>
<Fragment key={post.id}>
<PostTitle title={post.title} />
<PostBody body={post.body} />
</Fragment>
);
}
You can inspect the DOM to verify that there are no wrapper elements
around the Fragment children:
const posts = [
{ id: 1, title: 'An update', body: "It's been a while since I poste
{ id: 2, title: 'My new blog', body: 'I am starting a new blog!' }
];
https://react.dev/reference/react/Fragment 5/7
20/02/2025, 09:02 <Fragment> (<>...</>) – React
Show more
PREVIOUS
Components
NEXT
<Profiler>
https://react.dev/reference/react/Fragment 6/7
20/02/2025, 09:02 <Fragment> (<>...</>) – React
uwu?
Describing the UI
Adding Interactivity
Managing State
Escape Hatches
Community More
Acknowledgements Terms
https://react.dev/reference/react/Fragment 7/7