Return multiple elements
A component needs to return multiple sibling elements where one JSX element is expected.
React 19+ · Component
Fragment groups multiple JSX elements without adding a wrapper node to the DOM. Use <>...</> for simple groups, or explicit <Fragment> when a key or ref is needed.
Fragment groups several JSX children as one renderable unit without inserting an extra DOM element. Use the shorthand for ordinary groups; use the named component when a key or ref is required. A Fragment ref exposes a FragmentInstance for first-level DOM-child interaction.
<Fragment>{children}</Fragment>
<>{children}</>| Name | Type | Description |
|---|---|---|
ref | optional ref | A ref object or callback; React assigns a FragmentInstance for interacting with the Fragment's wrapped DOM nodes. |
A JSX Fragment grouping its children without adding a wrapper node to the DOM.
import { Fragment } from 'react';
export default function ContactList({ contacts }) {
return (
<ul>
{contacts.map(contact => (
<Fragment key={contact.id}>
<li>{contact.name}</li>
<li>{contact.email}</li>
</Fragment>
))}
</ul>
);
}Use the explicit Fragment form when each mapped item must contribute multiple sibling elements and needs a key.
A component needs to return multiple sibling elements where one JSX element is expected.
A mapped item must render multiple sibling nodes while retaining a stable key.
DOM interaction is needed across a Fragment's first-level children without adding a wrapper.
A Fragment groups multiple elements where React expects one element, but it does not add a wrapper node to the resulting DOM. The shorthand <>...</> is the usual equivalent of <Fragment>...</Fragment>.
Follow-up: When is the explicit form necessary? Use <Fragment> when a group needs a key or a ref, because the shorthand cannot express those props.
A key identifies each grouped item when mapping multiple elements, so use the explicit Fragment component with key={...}. The shorthand cannot receive a key.
Follow-up: Why not add a div instead? A div changes the DOM structure, while Fragment grouping leaves the resulting DOM unchanged.
A Fragment can accept a ref and React supplies a FragmentInstance. That object provides methods for interacting with the Fragment's first-level DOM children.
Follow-up: What syntax is required? Import Fragment from react and render <Fragment ref={yourRef}>...</Fragment>; <>...</> cannot receive the ref.
FragmentInstanceuseRefkey