Skip to content

How to Fix React Fragment Key Prop Missing

DodaTech Updated 2026-06-26 1 min read

The Problem

In this quick-fix, you'll learn how to add key props to React Fragments in list rendering. This matters because React requires key props for array elements shorthand syntax doesnt support keys. In real-world applications, this pattern appears in rendering lists of description lists table rows in map iterations.

The Wrong Way

function ItemList({ items }) {
  return items.map(item => <>
    <dt>{item.term}</dt>
    <dd>{item.desc}</dd>
  </>);
}
Warning: Each child in a list should have a unique key prop

The Right Way

function ItemList({ items }) {
  return items.map(item => (
    <React.Fragment key={item.id}>
      <dt>{item.term}</dt>
      <dd>{item.desc}</dd>
    </React.Fragment>
  ));
}
No warning -- key properly assigned to Fragment

Prevention

  • Use <React.Fragment key={...}> not <> in lists
  • Provide stable unique keys for mapped elements
  • Keys only need uniqueness among siblings

FAQ

### Why doesnt shorthand syntax support keys??

<> transpiles to React.createElement(React.Fragment, null, children). No way to pass attributes on shorthand. Use explicit for keys.

Can I use a div wrapper instead??

Yes but it adds unnecessary DOM nodes. Fragments exist to avoid extra markup.

How to handle fragments in nested maps??

Use explicit Fragment key for each level. Combine keys: key={parent.id + '-' + child.id}.

This guide is brought to you by DodaTech — built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro