react
render_warning
ai_generated
true
Warning: Encountered two children with the same key, `keyValue`. Keys should be unique so that components maintain their identity across updates.
ID: react/react-duplicate-key-warning
93%Fix Rate
95%Confidence
140Evidence
2021-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 18 | active | — | — | — |
Root Cause
Two or more sibling elements in a list have the same key prop. React uses keys for reconciliation; duplicates cause incorrect DOM updates, lost state, and stale UI.
genericWorkarounds
-
95% success Use a unique, stable identifier from the data as the key (e.g., database ID)
items.map(item => <Item key={item.id} data={item} />)Sources: https://react.dev/learn/rendering-lists#where-to-get-your-key
-
90% success Generate stable IDs with crypto.randomUUID() at data creation time, not at render time
When adding items: setItems([...items, { id: crypto.randomUUID(), ...newItem }])
Dead Ends
Common approaches that don't work:
-
Use array index as the key
55% fail
Index keys cause state bugs when items are reordered, inserted, or deleted. React cannot distinguish moved items from new ones.
-
Use Math.random() or Date.now() as key
90% fail
Generates a new key every render, destroying and recreating all components each time. Kills performance and loses all component state.
Error Chain
Preceded by:
Frequently confused with: