React Missing Key Prop Warning
Fix 'Each child in a list should have a unique key' warning in React. Learn why keys are important and how to choose good key values.
What Does This Error Mean?
This React warning means you are rendering a list of elements without providing a key prop, or using array indices as keys. Keys help React identify which items have changed, been added, or been removed in a list.
Common Causes
Missing key prop on mapped elements
Using array index as key (ok for static lists, bad for dynamic)
Duplicate key values when items share the same identifier
Key prop set on a Fragment instead of the child element
Using Math.random() as key (causes unnecessary remounting)
How to Fix It
Add unique keys from data
Use a unique identifier from your data as the key.
const users = [
{ id: 1, name: "Alice" },
{ id: 2, name: "Bob" }
]
// ✅ Use unique id from data
return (
<ul>
{users.map(user => (
<li key={user.id}>{user.name}</li>
))}
</ul>
)Use index as last resort
Only use array index for static lists that don't change order.
// ✅ Static list: index is fine
const colors = ["red", "green", "blue"]
return (
<div>
{colors.map((color, i) => (
<span key={i}>{color}</span>
))}
</div>
)
// ❌ Dynamic list: index causes bugs
// When items are added/removed/reordered, indices shiftGenerate stable IDs if none exist
Create stable identifiers using a combination of properties.
const items = [
{ name: "Apple", type: "fruit" },
{ name: "Carrot", type: "vegetable" }
]
// Create composite key if no unique id
return items.map(item => (
<li key={`${item.type}-${item.name}`}>
{item.name}
</li>
))Related Tools
Use these tools to debug and fix this error:
Related Errors
Other common errors in this category:
401 Unauthorized Error
Learn what a 401 Unauthorized error means, common causes, and how to fix authentication failures in your web applications.
403 Forbidden Error
Learn what 403 Forbidden means, how it differs from 401, and how to fix access denied errors in your applications.
404 Not Found Error
Learn what 404 Not Found means, common causes, and how to fix broken links and missing resources on your website or API.
429 Too Many Requests Error
Learn what 429 Too Many Requests means, how rate limiting works, and how to handle or avoid hitting API rate limits.