React: Each child in a list should have a unique key prop
Keys tell React which item is which between renders. Use stable ids, avoid index keys and put the key on the mapped element, not on a wrapper.

Introduction & Quick Summary
React prints a console warning that stops teams from shipping clean builds:
Warning: Each child in a list should have a unique "key" prop.
Check the render method of `TodoList`. See https://react.dev/link/warning-keys for more information.Quick answer: an array of elements rendered by map() needs a stable, unique key on each sibling. React uses that key to match elements between renders; without it, the reconciler falls back to position and warns.
{todos.map((todo) => (
<li key={todo.id}>{todo.title}</li>
))}The warning is about identity, not formatting. A key taken from a database id preserves component state across reorders; an array index keeps state attached to a slot instead of an item. This guide explains how keys drive reconciliation, why index keys corrupt state, how keys work with fragments and nested lists, and when the duplicate-key warning appears.
Core Mechanics, Signatures & Reproducible Setup
key is a special prop that React reads before rendering. It is stored on the element, compared with the previous render, and never forwarded to the component.
type Todo = { id: string; title: string; done: boolean };
function TodoList({ todos }: { todos: Todo[] }) {
return (
<ul>
{todos.map((todo) => (
<li key={todo.id}>{todo.title}</li>
))}
</ul>
);
}Reproduce the warning:
function Bad({ items }: { items: string[] }) {
return (
<ul>
{items.map((item) => (
<li>{item}</li> // no key
))}
</ul>
);
}React reports the warning once per list per render pass. In React 18 and earlier it appears in the console; React 19 still warns but no longer prints the link text inside the message in every build, and a list with no keys at all in a StrictMode dev build can surface twice because effects run twice.
| Render shape | Needs keys | Why |
|---|---|---|
items.map(...) returning one element | yes | array of siblings |
literal siblings <A /><B /> | no | static positions are stable |
items.map(...) returning a fragment | yes, on the fragment | fragments are siblings too |
| nested map inside a map | yes, on both | each array is its own sibling list |
Array.from({ length: n }) | yes | an array is rendered |
conditional {flag && <X />} | no | single child, position stable |
| Key source | Stable across reorder | Safe for stateful children |
|---|---|---|
| database id | yes | yes |
| generated uuid stored in the item | yes | yes |
| array index | no | no |
crypto.randomUUID() in render | no, changes every render | remounts every render |
| title or email string | until it is edited | breaks when edited |
composite id + variant | yes | yes, lets variants remount |
Key Comparison Table
| Warning or symptom | Cause | Fix |
|---|---|---|
Each child in a list should have a unique "key" | element returned from map has no key | add a stable key |
Encountered two children with the same key | duplicate ids, or index plus id collision | make keys unique among siblings |
| Input loses focus or value after reorder | index key moved with the slot | use an item id |
| Component state jumps to the wrong row | index key, or keys reused across lists | key by identity |
key is undefined inside the child | reading props.key | pass the value as a normal prop |
| List re-mounts on every keystroke | key generated during render | generate the id once, store it |
| Warning only in dev, never in build | React strips the warning in production | the bug is real, do not ignore it |
| Pattern | Correct | Wrong |
|---|---|---|
| Key on list item | <li key={todo.id}> | key on the wrapper outside the map |
| Key on component | <Row key={todo.id} todo={todo} /> | <Row todo={todo}><div key={todo.id} /></Row> |
| Key for fragments | <Fragment key={id}> | <> with children needing identity |
| Key for nested lists | outer key={group.id}, inner key={item.id} | same id namespace for both |
| Key for placeholders | key={"skeleton-" + i} for a static count | key={Math.random()} |
Practical Edge Cases, Error Fixes & Deep Dive Code Examples
1. map without a key and the wrapper mistake
// wrong: key on the parent, not the item
<ul>
<div key="list">
{items.map((item) => <li>{item}</li>)}
</div>
</ul>
// right
<ul>
{items.map((item) => <li key={item.id}>{item.label}</li>)}
</ul>The key must be on the element produced by the iterator callback, and it must be unique among its siblings, not globally. When a <div> wraps the list, the <li> elements still form their own sibling list and still need keys.
function Row({ item }: { item: Row }) {
return <li>{item.label}</li>;
}
{rows.map((row) => <Row key={row.id} item={row} />)}2. Duplicate keys
const groups = [
{ id: 1, name: "A" },
{ id: 1, name: "B" }, // duplicate from a bad join
];
{groups.map((g) => <li key={g.id}>{g.name}</li>)}
// Warning: Encountered two children with the same key, `1`.Duplicate keys make React reuse one subtree for both entries, so the second row can render the first row's state. Composite keys fix the case where one list intentionally holds two kinds of item:
{cells.map((c) => <Cell key={`${c.row}:${c.col}`} cell={c} />)}Values are coerced to strings: key={1} and key={"1"} collide.
3. Fragments: the invisible sibling
import { Fragment } from "react";
{rows.map((row) => (
<Fragment key={row.id}>
<dt>{row.term}</dt>
<dd>{row.definition}</dd>
</Fragment>
))}Short syntax <>...</> cannot take a key. When a map returns several siblings, use Fragment with a key, or return a wrapper element that takes one.
4. Index keys and state loss
function Reorderable() {
const [names, setNames] = useState(["Ada", "Grace", "Linus"]);
return (
<ul>
{names.map((name, i) => (
<li key={i}>
{name} <input placeholder="note" />
</li>
))}
</ul>
);
}Move "Ada" to the end and every <input> keeps the text that was typed in its position, so "Ada" appears to own the note that belonged to "Linus". With key={name} the components are matched to items and the notes follow their rows. Index keys are acceptable only for lists that never reorder, never filter and never insert in the middle.
5. Keys are not props
function Item(props: { id: string; label: string }) {
console.log(props.id); // available if passed explicitly
// props.key does not exist
return <span>{props.label}</span>;
}
<Item key={item.id} id={item.id} label={item.label} />React consumes key (and ref in React 18 and earlier) before the component sees props. If a child needs the id, pass it again under another name; the warning that follows "key is not a prop" is usually a console.log returning undefined.
6. Generated ids and keys in async data
// wrong: a new id every render remounts every row
{items.map((item) => <Row key={crypto.randomUUID()} item={item} />)}
// right: generate once when the item is created
const [items, setItems] = useState(() =>
initial.map((i) => ({ ...i, key: crypto.randomUUID() }))
);Keys must be deterministic for a given item. A random key destroys and recreates the subtree on each render, which resets inputs, aborts animations and reruns effects. Use the JSON formatter to check that the API payload actually carries a unique id, and the diff checker to compare two rendered trees when a reorder bug is hard to see.
Common Compilation/Runtime Mistakes & Version Gotchas
- Adding keys only where the warning points. React reports the component that rendered the list, not the inner list. A warning in
Tablemay come from amapthree levels down. - Suppressing the warning. There is no supported way to disable it, and silencing the console hides real state bugs rather than fixing them.
- Assuming keys are required for correctness everywhere. They are required for arrays only. Static JSX does not need them, and adding them there is noise.
- Using
keyto force a re-mount of a single child. This works, but it also destroys state and effects, so an explicituseEffectdependency is usually clearer. - Mixing keyed and unkeyed children. A list where some entries come from
mapand others are literal is still one sibling list; the literal children do not need keys, but the mapped ones do. - React 19 changes.
refis now a normal prop, butkeyis still reserved; the warning text and the link changed, the rule did not. React 19 also reports duplicate keys more consistently in production builds. - Server Components. Keys work the same way in Server Components, and a list rendered on the server that lacks keys still warns during the server render, so the warning can appear in the terminal rather than the browser.
Keys are the cheapest correctness tool React gives you: one stable string per item, chosen from data rather than position, and list bugs, focus loss and state drift mostly disappear.
Official documentation: Rendering lists and the Fragment reference.
Official references
primary documentationThe React documentation that defines the behaviour this guide explains.
Try matching browser tools
All toolsSmall utilities that fit React work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related React guides
All React guidesReact 19: Support for defaultProps will be removed
React 19 ignores defaultProps on function components, so a default becomes undefined. Move defaults into the parameter list and handle null honestly.
react-hook-form with zod 4: resolver type errors after the upgrade
Zod 4 split input from output and resolvers v5 re-typed Resolver. Drop the generic, or pass all three, and the errors disappear.
React Profiler API: Measuring Render Timings and Identifying Wasted Re-Renders
actualDuration versus baseDuration, phase names that tell you who triggered a commit, and how to ship the numbers without flooding a backend.
React useOptimistic and useFormStatus: Instant UI Feedback in React 19
Optimistic state that reverts by itself when the Action fails, plus form pending status read from inside the form instead of lifted state.
More in React
All React guidesThe guides filed next to this one in React, in library order.