liveBook · Manning

React.Fragment

As explained in React Quickly, Second Edition

React.Fragment is a built-in React component that groups multiple children without producing a corresponding DOM element or HTML output.

React.Fragment groups sibling elements when React requires one parent element, without adding a corresponding DOM element or HTML output. This avoids the extra wrapper that a <div> would create. section 2.3.3

Group a heading and link

Use the Fragment component when rendering multiple elements together: `const group = React.createElement(React.Fragment, null, title, link);` The heading and link render as siblings, while the Fragment itself does not appear in the HTML. section 2.3.3

In JSX, choose between the explicit component and its shorthand:

  • Use `<Fragment>...</Fragment>` after importing `Fragment` from React when the fragment needs properties such as `key`. section 3.2.9
  • Use `<>...</>` for ordinary fragments when no attributes or properties are needed. section 3.2.9
  • Use a keyed Fragment when mapping data to multiple sibling elements, such as each `<dt>` and `<dd>` pair in a definition list. section 3.2.9

How React Quickly, Second Edition covers it

How deep it goes
Defines explicit and shorthand syntax, then applies keyed Fragments to mapped definition-list entries.
Examples
Demonstrates heading-and-link siblings and dog-breed definition lists rendered with keyed Fragments.
What it assumes
Assumes basic React rendering and JSX, while introducing fragments from the single-element rendering constraint.
What you can do after
Apply it via React and JSX to group siblings without wrapper markup and render mapped pairs with stable keys.
How it connects
Connects React.Fragment with JSX, ReactDOM.createRoot, component returns, lists, keys, and definition lists.

Also explained in

Compare how 2 books explain React.Fragment →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of React Quickly, Second Edition. The section links point to the parts of the book it draws on.