react-key-prop

Guide React key prop usage for stable list rendering and reconciliation.

Updated Apr 17, 2026
One-click install
npx skills add https://github.com/Chris-Maskey/opencode-config --skill react-key-prop-chris-maskey
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: react-key-prop
Source: https://github.com/Chris-Maskey/opencode-config/tree/main/skills/react-key-prop
Command: npx skills add https://github.com/Chris-Maskey/opencode-config --skill react-key-prop-chris-maskey

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Explains how to choose and apply the React key prop so list items keep stable identity during reconciliation, preventing UI glitches and state mismatches when rendering or updating lists.

Core Features & Use Cases

  • Principled Guidance: Emphasizes using stable, unique IDs from your data rather than indexes or values generated during render.
  • Practical Patterns: Recommends creating one-time IDs on data load when items lack identifiers and describes the rare conditions where index keys are acceptable.
  • Troubleshooting: Helps diagnose and fix issues caused by keys that force unnecessary remounts, break input state, or misapply reconciliation after sorting, filtering, or splicing.

Quick Start

Ask the assistant to analyze a React component that maps an array to elements and recommend stable keys and code changes to replace index or runtime-generated keys.

Frequently Asked Questions about react-key-prop

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why does my React list lose input state when I sort or filter items?

React list rendering loses input state during sorting or filtering because unstable keys cause component state mismatches during reconciliation. Using array indexes as keys forces React to misapply state to the wrong DOM nodes when the list order changes.

How do I choose stable keys for dynamic React lists?

Choose stable keys for dynamic React lists by applying unique identifiers from your data, such as database IDs. If items lack identifiers, generate one-time IDs using nanoid on data load to maintain stable component identity during reconciliation.

When is it acceptable to use array indexes as keys in React?

Array indexes are acceptable as React keys only in rare conditions where the list is strictly static, never reordered, filtered, or spliced. For dynamic lists, index keys break reconciliation and cause incorrect DOM updates and state bugs.

Can I use React's useId hook to generate keys for list items?

You should not use the useId hook to generate React list keys. Generating keys during render creates new identifiers on every render cycle, forcing unnecessary component remounts and breaking the stable identity required for proper state reconciliation.

What is the best way to fix React key prop warnings and state bugs?

Fix React key prop warnings and state bugs by replacing index or runtime-generated keys with stable unique IDs. Apply one-time generated identifiers when data loads to ensure list items maintain correct identity during DOM reconciliation.