Fragments in React

From the React Components & JSX cheat sheet · JSX Fundamentals · verified Jul 2026

Fragments

Return multiple elements without wrapper

javascript
import { Fragment } from 'react'

// Long syntax with Fragment
function LongForm() {
  return (
    <Fragment>
      <h1>Title</h1>
      <p>Paragraph</p>
    </Fragment>
  )
}

// Short syntax (preferred)
function ShortForm() {
  return (
    <>
      <h1>Title</h1>
      <p>Paragraph</p>
    </>
  )
}

// Only Fragment can have key prop
function ListItems({ items }) {
  return (
    <>
      {items.map(item => (
        <Fragment key={item.id}>
          <dt>{item.term}</dt>
          <dd>{item.definition}</dd>
        </Fragment>
      ))}
    </>
  )
}
💡 Fragments avoid extra wrapper divs
📌 Use <> </> shorthand in most cases
⚡ Only Fragment accepts key prop
jsxfragments

More React tasks

Back to the full React Components & JSX cheat sheet