Skip to content

react/jsx-key Correctness

This rule is turned on by default.

What it does

Enforce key prop for elements in array

Why is this bad?

React requires a key prop for elements in an array to help identify which items have changed, are added, or are removed.

Example

Examples of incorrect code for this rule:

jsx
[1, 2, 3].map((x) => <App />);
[1, 2, 3]?.map((x) => <BabelEslintApp />);

Examples of correct code for this rule:

jsx
[1, 2, 3].map((x) => <App key={x} />);
[1, 2, 3]?.map((x) => <BabelEslintApp key={x} />);

How to use

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny react/jsx-key
json
{
  "rules": {
    "react/jsx-key": "error"
  }
}

References

Released under the MIT License.