Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Next.js and React

React logs that a props object with a key is spread into JSX

Your error

A props object containing a "key" prop is being spread into JSX:2 more lines it can show

Fix it fast

Most common cause, 1 of 2

Your own data object has a field called key

Split key off before the spread and give it to the element on its own.

Fix
{rows.map((row) => {
  const { key, ...rest } = row;
  return <ListItem key={key} rowId={key} {...rest} />;
})}
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

A props object containing a "key" prop is being spread into JSX is a development message from React's JSX runtime: an object passed with {...props} carries a key field. Pull it out first with const { key, ...rest } = props, then render <Item key={key} {...rest} />. Seen in React 18.3 and 19.3; production builds do not print it.

  • Applies to React 19.3.1, React 18.3.1, MUI Material 9.5 Autocomplete
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Read the two example lines in the message. The tag in <Name {...props} /> is where the spread happens, and the field list after key: someKey shows what the object holds. Search your code for spreads into that tag; no hit means the spread sits inside a package.

Run this first
grep -rnE "<ListItem[^>]*\{\.\.\." src/

Then find the line you see in this list and open its fix:

  1. 1Your own data object has a field called keyThe field list shows your own names, such as key: someKey, title: ..., price: ..., and the tag is one of your components
  2. 2A library callback hands you props that include keyThe field list holds attributes and handlers you never wrote, such as role, aria-* fields, className and onClick

What does the error look like?

  • A props object containing a "key" prop is being spread into JSX:
  • React keys must be passed directly to JSX without using spread:
  • Warning: A props object containing a "key" prop is being spread into JSX:

Cause 1 of 2

Your own data object has a field called key

You seeThe field list shows your own names, such as key: someKey, title: ..., price: ..., and the tag is one of your components

Check

React prints the key spread message whenever the object given to a JSX tag through {...props} owns a key property. A record that stores key as an ordinary data field trips it as soon as the whole record is spread into a component.

Check
grep -rnE "\{\.\.\.(item|row|record|props)\}" src/

Fix

Split key off before the spread and give it to the element on its own. If the component also needs that value, pass it again under another name, since a component never receives key as a prop.

Fix
{rows.map((row) => {
  const { key, ...rest } = row;
  return <ListItem key={key} rowId={key} {...rest} />;
})}

Verify

Reload the page in development with the console open. The message is gone and the list renders as before.

Verify
npm run dev

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 2 of 2

A library callback hands you props that include key

You seeThe field list holds attributes and handlers you never wrote, such as role, aria-* fields, className and onClick

Check

Some component APIs pass a ready-made props object into your render callback, and that object already includes key. MUI's Autocomplete renderOption is one such API: its demos take key off the first argument before spreading the rest onto an li.

Check
grep -rn "renderOption" src/

Fix

Inside the callback, separate key from the rest the way MUI's own demos do, then set key on the returned element and spread only the remainder.

Fix
renderOption={(props, option) => {
  const { key, ...optionProps } = props;
  return (
    <li key={key} {...optionProps}>
      {option.label}
    </li>
  );
}}

Verify

Open the dropdown again. The options render and the console stays clean.

Verify
npm run dev

Confirmed by raw.githubusercontent.com

Did this fix it?

How do I stop it coming back?

  • Rename key fields to id when you shape API data for the UI, so whole records can be spread safely.
  • When a library gives you a props object in a callback, always destructure key out of it before spreading.
  • Keep the browser console visible during development and treat this message as a bug to fix, not noise.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: TaxiDex, QistLock, Taskvare.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.