React and web development

Use stable React keys for changing collections

Provide stable, unique keys so React preserves the correct component state when list items move, appear or disappear. Array indexes identify positions, not records. When a list reorders, index keys can attach focus, input values or expanded state to the wrong item. Framework conventions do not remove the need to test rendered HTML, keyboard interactions, browser compatibility and real user performance.

User experience and browser behavior

Array indexes identify positions, not records. When a list reorders, index keys can attach focus, input values or expanded state to the wrong item.

  • Start from native browser semantics
  • Test loading, error and interaction states
  • Measure user experience on representative devices

Implementation approach

Use a persistent item identifier as a key, create IDs when records are created rather than during rendering, and avoid duplicate keys within the same sibling list.

  • Confirm the responsible owner
  • Apply the change to a representative case
  • Document decisions and exceptions

Practical example

A sortable task list uses each task's database ID; moving an item does not transfer its unsaved input draft to the task that now occupies its previous index.

  • Reproduce the starting situation
  • Apply the described approach
  • Check the user-facing result

Verification and follow-up

Test insertion at the start, deletion, sorting and filtering with stateful child components; confirm no key warnings and state remains with the intended record.

  • Test expected and failure cases
  • Compare with the recorded baseline
  • Agree the next review date and owner

Questions to keep in view

When should a team use this react and web development guide?

Provide stable, unique keys so React preserves the correct component state when list items move, appear or disappear.

What should be checked before rollout?

Test insertion at the start, deletion, sorting and filtering with stateful child components; confirm no key warnings and state remains with the intended record.