Rules
no-missing-key
Disallows missing 'key' on items in list rendering.
Full Name in eslint-plugin-react-x
react-x/no-missing-keyFull Name in @eslint-react/eslint-plugin
@eslint-react/no-missing-keyPresets
x
recommended
recommended-typescript
recommended-type-checked
strict
strict-typescript
strict-type-checked
Rule Details
React needs keys to identify items in the list. If you don’t specify a key, React will use the array index as a key, which often leads to subtle and confusing bugs.
Common Violations
Invalid
interface MyComponentProps {
items: { id: number; name: string }[];
}
function MyComponent({ items }: MyComponentProps) {
return (
<ul>
{items.map((todo) => <Todo {...todo} />)}
</ul>
);
}Valid
interface MyComponentProps {
items: { id: number; name: string }[];
}
function MyComponent({ items }: MyComponentProps) {
return (
<ul>
{items.map((todo) => <Todo key={todo.id} {...todo} />)}
</ul>
);
}Resources
Further Reading
See Also
react-x/no-array-index-key
Disallows using an item's index in the array as its key.react-x/no-duplicate-key
Prevents duplicatekeyprops on sibling elements when rendering lists.react-x/no-implicit-key
Prevents implicitly passing thekeyprop to components.