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

Suggestion: no-redundant-key #3880

Open
SimonSchick opened this issue Jan 16, 2025 · 1 comment
Open

Suggestion: no-redundant-key #3880

SimonSchick opened this issue Jan 16, 2025 · 1 comment

Comments

@SimonSchick
Copy link
Contributor

SimonSchick commented Jan 16, 2025

I noticed that after refactorings we sometimes forgot to remove the key on the root fragment of a new component, this seems to be entirely redundant and just add overhead.

example:

const Component: FC = () => {
          // v key is redundant here
   return <p key={1}>test</test>;
}

This would be effectively the counter-rule to `https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-key

I think a good heuristic would be to match any fragment that is not contained within a callback eg. Array.map.

@ljharb
Copy link
Member

ljharb commented Jan 16, 2025

key does serve a purpose, even outside a list - in other words, it's not redundant. See https://kentcdodds.com/blog/understanding-reacts-key-prop

What this means is that I'm not sure there's any way to statically identify a key prop that should be removed, since potentially all of them could be meaningful.

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

No branches or pull requests

2 participants