Why can an array-index key break an editable list?
Understand the idea, explain it in your own words and use the rubric to find your next learning gap.
The idea behind the question
Keys identify sibling elements between renders. A key tied to position can associate state with a different item after insertion or reordering.
Insert a passenger above a row containing a partially edited name.
A practical way to learn it
Build a three-row editable list and compare index keys with stable IDs after moving a row.
Open React project studioThe related tool opens separately; your interview answer stays here. Written practice is self-guided, without automatic code grading.
Build an explanation you understand
- State what the concept does in plain language.
- Apply it to the example and make your assumptions explicit.
- Explain a trade-off, failure case and how you would test it.
- Distinguish your actual experience from a proposed approach.
How would you explain it?
Single-question timers reset on refresh. Full mock sessions can resume from this browser.
Strengthen your explanation
Compare reasoning, not identical wording. Reference answers describe a possible approach; replace hypothetical statements with truthful details from your own work.
One way to answer
I would use an item's stable identity as its key, particularly when rows contain input state or can move. An array index identifies a position, so after insertion React may preserve the row instance for the wrong logical item. I would reproduce the bug by editing a row and reordering the list. I would also avoid generating random keys during rendering because that causes remounts and lost state. Keys are scoped to siblings and are not automatically passed as ordinary component props.
What a strong explanation should cover
Tick only the points your own answer addresses. This is self-assessment, not AI scoring.
0 / 3 points self-reportedWatch out for
- Using Math.random() as a render-time key.
Now go one level deeper
- When might an index be acceptable?
- Why would changing a key deliberately reset a form?
Further reading
Further-reading links support learning; the reference is Sukoaa-authored, not an official employer answer key.