flpbalada/fb-skills

react-key-prop

Choose correct React key props for lists and remounts.

First seen May 4, 2026

Installation

$ npx skills add flpbalada/fb-skills --skill react-key-prop

Summary

  • Choose correct React key props for lists and remounts.
  • Use when mapping arrays, rendering dynamic lists, sorting/filtering/reordering items, debugging list state bugs, avoiding index keys, or intentionally resetting component state with a key.
  • For general local state updates use react-use-state; for effect-based resets use react-useeffect-avoid.

Similar popular skills

Related neighbors and high-traction skills in the same topics — useful to compare before installing.

Also in this package

Other skills from flpbalada/fb-skills · top by installs.

npx skills add flpbalada/fb-skills

Browse all from flpbalada/fb-skills

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Not declared
Cursor Not declared
Codex Not declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Not declared
Cline Not declared
OpenCode Not declared

Repository health

Stars 7
Default branch main
Open issues 0
Status Active

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 1,786 B
  • docs SUMMARY.md 369 B

History

  1. First seen on skills.sh
  2. First recorded snapshot · 15 installs

SKILL.md

React Key Prop

Goal

Give React stable item identity. Use keys tied to data, not render position.

Rules

  • Always add key to rendered list items.
  • Prefer unique, stable IDs from data.
  • Generate missing IDs once when data is created or loaded.
  • Use the same key while the same item exists.
  • Do not generate keys during render.
  • Do not use Math.random() or Date.now().
  • Do not use useId() for list keys.
  • Avoid array index keys for dynamic lists.

Good Pattern

{todos.map((todo) => (
  <li key={todo.id}>{todo.text}</li>
))}

Missing IDs

Create IDs once, before render:

const itemsWithIds = data.map((item) => ({
  ...item,
  id: crypto.randomUUID(),
}));

Index Exception

Index key is acceptable only when all are true:

  • List is static.
  • Items are never inserted or removed from the middle.
  • Order never changes.
  • Items have no internal state.

Failure Mode

Index represents position. When order changes, React reuses the wrong component. Result: stale state, wrong input values, broken animations, or unexpected focus.

References

Output

  • Stable key choice.
  • Note when data lacks IDs.
  • Fix for any index, random, date, or useId key.