What is the purpose of keys in React lists and what makes a good key?
Updated Apr 23, 2026
Short answer
In React, keys are special attributes used in lists to help React identify which items have changed, been added, or removed.
A good key is a stable, unique, and predictable identifier for each list item, such as an ID from a database.
Deep explanation
Why React needs keys
When rendering lists, React needs to efficiently update the UI when data changes.
Without keys, React would:
- Re-render entire lists unnecessarily
- Lose track of which item is which
- Cause performance issues and UI bugs
Keys help React perform reconciliation efficiently by matching elements between renders.
---
Example of a list with keys
function TodoList({ todos }) { return ( <ul> {todos.map(todo => ( <li key={todo.id}>{todo.text}</li> ))} </ul> );}Here:…
Unlock with a Pro subscription to view this section.
View pricingReal-world example
No real-world example available yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProCommon mistakes
No common mistakes listed yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProFollow-up questions
No follow-up questions available yet.
Unlock with a Pro subscription to view this section.
Upgrade to Pro