eslint-plugin-react icon indicating copy to clipboard operation
eslint-plugin-react copied to clipboard

[Bug]: react/jsx-key rule is not applied when using return statement and ternary operator in iterator

Open Dorianspeed opened this issue 5 months ago • 0 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues and my issue is unique

Description Overview

Brief description

As described in the title, react/jsx-key is not applied when using return statement and ternary operator in iterator. It's working when not using return statement as shown in my below picture.

Picture showing the current issue

Image

Code to reproduce error

Here is a small code snippet to reproduce the current error:

import { Fragment } from 'react';

const ITEMS = ['bar', 'foo'];

export default function BugIssue() {
  return (
    <Fragment>
      {ITEMS.map((item) => {
        return item === 'bar' ? <div>{item}</div> : <span>{item}</span>;
      })}
    </Fragment>
  );
}

Expected Behavior

An error should be displayed when using return statement and ternary operator.

=> Missing "key" prop for element in iterator

eslint-plugin-react version

v7.37.3

eslint version

9.27.0

node version

v22.15.0

Dorianspeed avatar May 22 '25 10:05 Dorianspeed