Course contentsShow
← React
Lesson 154 of 2,3965. Lists and KeysFree lesson

What Makes a Good Key

Characteristics of ideal keys: stable, unique, and derived from data rather than render order or random generation.

What Makes a Good Key

What you'll learn: The three essential characteristics that make a key prop truly effective in React applications.

You already know that keys must be unique among siblings and stable across renders. But what actually makes a key good? Not all unique, stable values are created equal—some keys cause subtle bugs while others keep your lists rendering flawlessly.

The Three Pillars of a Good Key

1. Stable A good key doesn't change between renders unless the item itself fundamentally changes. Think of it like a social security number—it identifies a person throughout their entire life, not just for today.

2. Unique Among siblings in the same list, each key must be different. Two items can't share the same key without confusing React about which is which.

3. Derived from Data Here's the crucial part: keys should come from your data, not from how or when you render it. Use database IDs, product SKUs, email addresses, or any identifier that's inherent to the item itself.

What to Avoid

Never use array index as a key if your list can reorder, filter, or have items added/removed. The index describes position, not identity.

Never generate random keys (like Math.random() or uuid()) during render. Every render creates a new key, breaking stability and causing React to destroy and recreate components unnecessarily.

The Mental Model

Think of a classroom attendance sheet. Good keys are like student ID numbers—they stay with the student even if they change seats. Bad keys are like seat numbers—they tell you nothing about who's sitting there when students shuffle around.

Key Takeaway: A good key is stable across renders, unique among siblings, and comes directly from your data—never from render order or random generation.