React uses keys to track list items, but using the array index can create UI bugs.
📌 Problem with index as key:
• Wrong item gets updated
• Animations break
• Items reorder incorrectly
📘 Better Approach:
Always use a unique ID from your data:
<li key={item.id}>{item.name}</li>
✨ Rule:
Index as key = only safe when list never changes.
Better keys → More stable UI. 🚀
Top comments (1)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.