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

feat: add new rule react/jsx-key #263

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

l2ysho
Copy link

@l2ysho l2ysho commented Jun 8, 2022

Turn on rule to detect missing key prop in JSX.

  • main reason is ensure valid react syntax.
  • one downside can be a need to refactor old projects.
  • feel free to discuss or suggest reviewers

Examples of incorrect code for this rule:

[<Hello />, <Hello />, <Hello />];
data.map(x => <Hello>{x}</Hello>);
<Hello {...{ key: id, id, caption }} />

In the last example the key is being spread, which is currently possible, but discouraged in favor of the statically provided key.

Examples of correct code for this rule:

[<Hello key="first" />, <Hello key="second" />, <Hello key="third" />];
data.map((x) => <Hello key={x.id}>{x}</Hello>);
<Hello key={id} {...{ id, caption }} />

more info about jsx/key-prop

New rule to detect missing key prop in jsx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant