Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: The Warning 'Each child in a list should have a unique "key" prop.' Should Provide the Duplicate Key #29116

Open
jwalkerinterpres opened this issue May 16, 2024 · 1 comment

Comments

@jwalkerinterpres
Copy link

React version: 8.3.0

Steps To Reproduce

  1. Repeat content with the same key
  2. Get a warning (in your browser dev tools console):

Each child in a list should have a unique "key" prop.

Link to code example:

No link needed, it's a single line of code:

<ul>{ [1,2,3].map(num => <li key="sameKey">{num}</li> }</ul>

The current behavior

image

The expected behavior

The warning essentially says "You've got duplicate values". But, React knows exactly what key it saw duplicated, right?

That key (eg. "sameKey" in my example), would be useful for debugging purposes, so why not report it?

Each child in a list should have a unique "key" prop, but the key "sameKey" was seen at least twice.

@jwalkerinterpres jwalkerinterpres added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label May 16, 2024
@eps1lon eps1lon added Type: Enhancement and removed Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug labels May 22, 2024
@Shraghav
Copy link

    { [1,2,3].map(num =>
  • {num}
  • }

Here try to pass the sameKey as num as each num is different. Now you won't get any warnings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants