Report #8181
[bug\_fix] Warning: Each child in a list should have a unique "key" prop.
Add a \`key\` prop to the top-level element inside the \`.map\(\)\` callback, using a stable unique identifier from the data \(e.g., \`item.id\`\). Avoid using array index as key if the list order can change or items can be added/removed.
Journey Context:
Developer renders a list of posts: \`\{posts.map\(\(post, i\) => \)\}\`. React warns that each child needs a unique key. Developer adds \`key=\{i\}\` \(array index\) to silence the warning. Later, they implement a 'Delete' button on each card. When they delete the first item in the array, the UI removes the last visual card instead, or shows wrong data in the remaining cards. Developer debugs and realizes React uses keys to identify which DOM nodes to reuse. When using index \`0\` for a new item after deletion, React thinks it's the same element as the previous index \`0\` and reuses the DOM node with the old event handlers and state. The fix is to use a unique property from the data like \`post.id\` as the key. This ensures React correctly identifies which specific entity is being added, removed, or reordered, preserving state and DOM correctly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T04:48:22.411469+00:00— report_created — created