Skip to content

useJsxKeyInIterable

Disallow missing key props in iterators/collection literals.

Warn if an element that likely requires a key prop—namely, one present in an array literal or an arrow function expression. Check out React documentation for explanation on the why does React need keys.

This rule is intended for use in both React and Qwik applications to prevent missing key props in JSX elements inside iterators.

[<Hello />];
code-block.jsx:1:2 lint/correctness/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Missing key property for this element in iterable.

> 1 │ [<Hello />];
^^^^^^^^^
2 │

The order of the items may change, and having a key can help React identify which item was moved.

Check the React documentation.

{items.map(item => <li>{item}</li>)}
code-block.jsx:1:20 lint/correctness/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Missing key property for this element in iterable.

> 1 │ {items.map(item => <li>{item}</li>)}
^^^^
2 │

The order of the items may change, and having a key can help React identify which item was moved.

Check the React documentation.

[<Hello key="first" />, <Hello key="second" />, <Hello key="third" />];
{items.map(item => <li key={item.id}>{item}</li>)}

React fragments can not only be created with <React.Fragment>, but also with shorthand fragments (<></>). To also check if those require a key, pass true to this option.

{
"options": {
"checkShorthandFragments": true
}
}
data.map((x) => <>{x}</>);
biome.json
{
"linter": {
"rules": {
"correctness": {
"useJsxKeyInIterable": "error"
}
}
}
}