Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
Keys let React match items between renders; an index changes when items are inserted, removed or reordered, so React can attach state and DOM to the wrong item.
When a list re-renders, React compares the old and new children by key to decide which elements stay, move, appear or disappear. A stable, unique key such as a database id keeps each item's state and DOM node tied to the right data. With the index as key, removing the first item shifts every key down by one, so React reuses components for different data; inputs can keep the wrong text and animations can jump. The index is acceptable only for static lists that never reorder or change length.