Report #98690
[bug\_fix] React console warning 'Each child in a list should have a unique "key" prop' and related bugs: list items losing focus/state, the wrong item updating, or duplicate rendering.
Provide a stable, unique key for every element returned directly from map\(\). Prefer a database ID, UUID, or other persistent identifier over the array index or Math.random\(\). Use when a single list item needs multiple root nodes. Ensure keys are unique among siblings and do not change between renders.
Journey Context:
Rendered a todo list with todos.map\(\(t, i\) => ...\). Adding a new item at the top shifted every existing item's key, so React reused the wrong DOM nodes; checked checkboxes jumped to the wrong rows. The console warned about missing unique keys. I first tried key=\{Math.random\(\)\}, which silenced the warning but destroyed performance because React recreated every element each render. The React docs on rendering lists state keys must be stable and unique among siblings. I switched to key=\{todo.id\} from the database. Reordering and deletion now preserve component state correctly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-28T04:36:41.553140+00:00— report_created — created