react-key-prop

Guide React key prop usage with stable data IDs for dynamic lists.

Updated Nov 28, 2025
One-click install
npx skills add https://github.com/davidsteinberger/dotfiles --skill react-key-prop-davidsteinberger
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: react-key-prop
Source: https://github.com/davidsteinberger/dotfiles/tree/main/opencode/.config/opencode/skills/react-key-prop
Command: npx skills add https://github.com/davidsteinberger/dotfiles --skill react-key-prop-davidsteinberger

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill guides users on the correct and incorrect usage of the key prop in React when rendering lists, preventing common bugs and performance issues.

Core Features & Use Cases

  • Stable Key Identification: Emphasizes using unique, stable IDs from data.
  • Avoids Anti-Patterns: Clearly illustrates why array indices and random keys are problematic for dynamic lists.
  • Use Case: When building a dynamic to-do list in React, this skill ensures you use a unique todo.id for each list item's key, preventing state corruption when items are added, removed, or reordered.

Quick Start

Use the react-key-prop skill to understand the best practices for assigning keys to list items in React.

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 component lose state when items are reordered?

React list components lose state during reordering when using array indices as keys. The key prop guides React's reconciliation process, and unstable keys cause it to incorrectly match elements, leading to state corruption and rendering bugs.

What is the best way to assign a key prop to dynamic list items in React?

The best way to assign a key prop in React is by using stable, unique data IDs from your dataset, such as a database ID. This ensures efficient rendering and prevents state bugs when list items are added, removed, or reordered.

When should I avoid using array indices as keys in React lists?

You should avoid using array indices as keys in React lists whenever the list is dynamic. Indices are anti-patterns for lists that can be reordered or modified, because they break React's reconciliation principles and cause incorrect component state matching.

How do I fix list rendering performance issues in React?

To fix list rendering performance issues in React, ensure each mapped component has a stable, unique key prop. Proper key assignment allows React's reconciliation algorithm to efficiently update the DOM without re-rendering unchanged components.

Are random keys safe to use for React list rendering?

Random keys are not safe for React list rendering because they are unstable. Generating new random keys on each render forces React to destroy and recreate list item components, which severely degrades frontend performance and resets internal state.