jsx-key
Configuration
Disallow missing key props in iterators / collection literals.
Rule Details
Warn if a JSX element that likely needs a key prop — namely, one inside an
array literal or returned from an arrow function / function expression passed
to Array.prototype.map or Array.from — is missing one.
Examples of incorrect code for this rule:
In the last example the key is being spread, which is currently possible but discouraged in favor of a statically provided key.
Examples of correct code for this rule:
Rule Options
checkFragmentShorthand (default: false)
When true, report the shorthand fragment syntax (<></>) used in arrays /
iterators, since shorthand fragments cannot carry a key. The reported
suggestion uses the configured pragma, e.g. React.Fragment or, with
settings.react.pragma/settings.react.fragment, Act.Frag.
checkKeyMustBeforeSpread (default: false)
When true, report any key prop that appears after a {...spread}
attribute. Required by React's new JSX transform.
warnOnDuplicates (default: false)
When true, report keys whose source-text value is identical within the same
container (array literal or JSX parent).
Key values are compared as raw source text. key="a" and key={'a'} do NOT
count as duplicates of each other — they are different source strings.
When Not To Use It
If you are not using JSX then you can disable this rule.
Also, if you frequently use arrow functions that return JSX but never render the JSX inside an iterable, you may want to disable this rule.