In this guide
A simple guide to this issue: 'Each child in a list should have a unique key prop' in React. Learn why it happens, what to check first, and how to fix it.
This is a warning, not a crash — but ignore it and you will eventually ship a bug where list items show the wrong state after sorting or deleting. Here is what keys actually do and how to fix the warning correctly.
The Warning
Warning: Each child in a list should have a unique "key" prop. Check the render method of YourComponent.
Why React Needs Keys
Keys tell React which DOM node maps to which item between renders. With stable keys, React can move, add, and remove the right elements instead of rebuilding the whole list — that is both a correctness and a performance feature.
The Fix: Use a Stable, Unique ID
{todos.map((todo) => (
<TodoItem key={todo.id} todo={todo} />
))}Why You Should Avoid the Array Index
key={index} silences the warning but reintroduces the bug it was protecting you from. When the list reorders or an item is removed, indexes shift and React reuses the wrong component instance — inputs keep old values, animations glitch, checkboxes tick the wrong row.
// ⚠️ Acceptable ONLY if the list is static and never reorders
{items.map((item, index) => <li key={index}>{item}</li>)}
// ✅ Prefer a real unique id
{items.map((item) => <li key={item.id}>{item.label}</li>)}No ID in Your Data?
Generate one when you create the item (crypto.randomUUID()), not during render. Generating it in render makes a new key every time, defeating the purpose.
Relevant Scaleup Infotech Services
Keep Reading
Fix React Search Results Showing the Wrong Data
Fix React search race conditions with request cleanup, cancellation, and stale-response checks. Includes code and a slow-network verification checklist.
5 min readFix Next.js Environment Variables Missing in Production
Fix missing Next.js production environment variables by checking build-time values, public prefixes, deployment settings, and the exact release artifact.
5 min readFix Laravel Queue Jobs Not Processing After Deployment
Recover Laravel queue jobs after deployment by checking the connection, queue name, workers, cached configuration, failed jobs, and restart behavior.
5 min read