QuizNot attempted
Spot the bug: uuid keys in render
1–4 to choose, Enter to submit
Show answer & explanation
Correct answer:
- Every row unmounts and remounts, because no key matches the previous render
- Keys must be unique AND stable across renders.
- A fresh uuid per render never matches last render's key, so React destroys every
<tr>and builds new DOM: slow for long lists, and focus, selection and any row state are lost. - Use the record's id (
key={row.id}) - if the data has none, assign ids once when it arrives, never during render.
- Not unique is enough: uniqueness without stability is exactly what forces the remount.
- Not reuses by position: a key that doesn't match is a new element
- position only matters with no keys or index keys.
- Not duplicate-key warning: uuids never collide, so React stays silent, which is why this survives review.