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

fix(jsx-key): detect missing keys in JSX elements pushed to arrays

Open holoflash opened this issue 1 month ago • 0 comments

I came across this today and thought I might as well try and fix it. The following wasn't triggering a warning, even though it should ( ? )

function EslintJsxKey() {
  const keylessItems = [];
  for (let i = 0; i < 4; i++) {
    keylessItems.push(<li>No Key!</li>);
  }
  return <ul>{keylessItems}</ul>;
}

While this is not the typical way one would do things in React, it felt like an easy one to handle so...why not? Perhaps there's more to this that I've missed, and there's a good reason for why this wasn't done before.

Similar to: https://github.com/jsx-eslint/eslint-plugin-react/issues/3937

holoflash avatar Oct 15 '25 20:10 holoflash