Skip to content

[Bug]: react/jsx-key rule doesn't detect missing keys in LogicalExpression in return statements #3931

Open
@yalperg

Description

@yalperg

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

The react/jsx-key rule fails to detect missing key props when JSX elements are conditionally rendered using the logical operators within return statements.

Code example

const list = [1, 2, 3, 4, 5, 6];

function Item({ item }) {
  return <p>{item}</p>;
}

function App() {
  return (
    <div>
      {list.map((item) => {
        return item < 4 && <Item item={item} />; // Missing key prop not detected
      })}
    </div>
  );
}

export default App;

Expected Behavior

The rule should detect and report the missing key prop error.

eslint-plugin-react version

v7.37.5

eslint version

v9.28.0

node version

v20.19.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions