When you render a list of items in React, why does each one need a key prop, and what can go wrong if you use the array index as the key?

technical-conceptual · Junior level · software-engineering

What the interviewer is really asking

Checks whether the candidate understands React reconciliation at a working level — that keys identify elements across renders — rather than treating the key warning as noise to silence.

What to say

What to avoid

Example answers

Strong: Keys let React's reconciliation tell which item is which between renders, so it only touches what changed. I use the record's id as the key. Index keys break when the list reorders — I've seen a typed-in form value jump to the wrong row after a sort, because React reused the element by position instead of by identity.

Weak: You add a key so React stops warning you in the console. I usually just put the index there since it's unique, and it works fine.

Want questions matched to your role? Paste a job title, job description, or CV and get a personalized set, or go Pro to unlock the full bank.