jsx/no-duplicate-key
Rule category
Correctness.
What it does
Prevents duplicate key
props on elements in the same array or a list of children
.
Why is this bad?
React uses keys to identify elements in an array. If two elements have the same key, React will not be able to distinguish them. This can lead to issues with state and rendering.
Examples
❌ Incorrect
const TodoList = ({ todos }) => (
<ul>
{todos.map((todo) => <Todo {...todo} key="key" />)}
</ul>
);
✅ Correct
const TodoList = ({ todos }) => (
<ul>
{todos.map((todo) => <Todo {...todo} key={todo.id} />)}
</ul>
);