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

Disallow missing `key` prop in JSX elements that likely require a `key` prop (react/jsx-key) #1369

Closed
feross opened this issue Aug 15, 2019 · 1 comment

Comments

@feross
Copy link
Member

commented Aug 15, 2019

https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-key.md

This rule caught a ton of instances where I forgot key in bitmidi.com, where I use Preact and the development tools don't seem to warn about this.


Warn if an element that likely requires a key prop--namely, one present in an
array literal or an arrow function expression.

Rule Details

The following patterns are considered warnings:

[<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.

The following patterns are not considered warnings:

[<Hello key="first" />, <Hello key="second" />, <Hello key="third" />];

data.map((x, i) => <Hello key={i}>{x}</Hello>);

<Hello key={id} {...{ id, caption }} />

@feross feross added this to the standard 14 milestone Aug 15, 2019

@feross feross changed the title Disallow missing `key` prop (react/jsx-key) Disallow missing `key` prop in JSX elements that likely require a `key` prop (react/jsx-key) Aug 15, 2019

@feross

This comment has been minimized.

Copy link
Member Author

commented Aug 15, 2019

Shipping in standard 14.

@feross feross closed this in 13e4bee Aug 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
1 participant
You can’t perform that action at this time.