What Makes a Key 'Stable'
What you'll learn: How to identify truly stable keys that won't cause React to lose track of your list items.
The Core Principle
A stable key is one that never changes for a given item, no matter what happens to the list around it. Even if you sort the array, filter it, reverse it, or add new items, each item keeps the exact same key it had before.
Think of it like a social security number—it identifies you specifically, regardless of where you stand in line, who else joins the line, or what order the line is sorted in. The number stays with you forever.
What Stability Looks Like
A stable key:
- Remains constant for an item across all renders
- Doesn't depend on array position or index
- Survives sorting, filtering, and reordering
- Ties to the data itself, not its presentation
// ✅ STABLE: User ID never changes for Alice
users.map(user => (
<UserCard key={user.id} user={user} />
))
Even if Alice moves from index 0 to index 5, user.id stays the same.
// ❌ UNSTABLE: Index changes when list reorders
users.map((user, index) => (
<UserCard key={index} user={user} />
))
When Alice moves to index 5, she gets a different key—React thinks she's gone and a new person appeared.
Why This Matters
Stable keys let React correctly track which items changed, moved, or stayed the same. Unstable keys break this tracking, causing state loss, performance issues, and the bugs you learned about earlier (wrong inputs keeping text, deletions shifting content).
Key Takeaway: A stable key is permanently bound to the data item itself—it never changes just because the list changed.