Report #11779
[bug\_fix] Each child in a list should have a unique 'key' prop \(Missing Key\)
Add a stable, unique \`key\` prop to the top-level element returned from the \`.map\(\)\` callback, using a unique ID from the data \(not the array index\).
Journey Context:
Developer renders a list of comments: \`\{comments.map\(\(comment, index\) => \{comment.text\}
\)\}\`. It displays fine initially. They add a feature to delete comments. After deleting the first comment, the UI shows the wrong text in the remaining rows—the text that belonged to the deleted item shifts to the next row, or input fields inside the list keep their values but point to wrong data. The browser console shows a warning: 'Each child in a list should have a unique "key" prop'. The developer initially ignores it or adds \`key=\{index\}\` to suppress the warning, but the bug persists. They investigate React reconciliation and learn that keys are used to identify items across renders. Without stable keys, React identifies elements by index, so removing item 0 makes the old item 1 become index 0, and React thinks the component just updated rather than being replaced, preserving internal state incorrectly. The fix is to use a unique property from the data, like \`comment.id\`: \`key=\{comment.id\}\`. Now React correctly tracks each specific comment, and deleting one removes the correct DOM node without state pollution.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T14:17:09.562459+00:00— report_created — created