Skip to content

[Bug]: react/jsx-key false positive on non-final arrays #3953

@hasparus

Description

@hasparus

Is there an existing issue for this?

  • I have searched the existing issues and my issue is unique
  • My issue appears in the command-line and not only in the text editor

Description Overview

react/jsx-key is raised on arrays inline in JSX even if they're immediately consumed and not subject to reconciliation.

<>
  {[
    <p>a</p> // Missing "key" prop for element in array ESLint[react/jsx-key],
    // ...
  ].map(
    (text, i) => <div key={i}>{text}</div>
  )}
</>

In this example, React doesn't need a key because on p because it's the only child, right?

Here's a repro:

https://eslint-online-playground.netlify.app/#eNp1Uk1PwzAM/StWLvuga8UJaZRJCLgjrssOoXVHoHGjJkWdqv53nCxMcFjVJI79/PGeMgnXVwWOytgW8083iq3A0Xa9h2agyuuO4OUcXa5gkgTQox96gnIXLgDT/nwClHanysLusj+O9+A43w+5UXb5G1t6HH0GegUPOyhr/Q1feHqY9JzQsXTAzJdqBaNSdBW9ZcFXtiSJTKBrNfm86qjRR2bCRLSJRCaosdGETzEEMzR9Z0CmjOKcIcW9pJTQo6r8azscNf3Hbmx0biIgZkhKanELNbTxvLSKZJM8UbrwNbpFt4X9Yr0u1vn06TLDq+LF6gd7zLzjn23e5sXhImee538mS0xd3rTKc6DqjEGqsU74OZ3XUvYLbrXpB/LaIHeBooDHugb/oR3oBk7dAKpHGJymI7yFKnB7dxOKHiStmDuLblX1pY7h4XTEgkeSUviTRSm2bJmuHlq24yxS1Pj9jDZMSZVGFzBJlysKhxo8Kzq2E59f5P9giPFLmMX8A30g604=

What is happening? / What is the error?

I see the warning where it's not needed.

What command(s) did you run to reproduce issue?

eslint

Expected Behavior

I'd expect the warning to appear only when the missing key causes a warning logged by React in development.

I can open a PR if it makes sense.

eslint-plugin-react version

v7.33.2

eslint version

v9.35.0

node version

v24

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions