react-key-prop

Guides correct usage of the key prop when rendering React lists.

Updated Apr 29, 2026
One-click install
npx skills add https://github.com/dev-khoi/AURA-conHack-2026 --skill react-key-prop-dev-khoi
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: react-key-prop
Source: https://github.com/dev-khoi/AURA-conHack-2026/tree/main/.opencode/skills/react-key-prop
Command: npx skills add https://github.com/dev-khoi/AURA-conHack-2026 --skill react-key-prop-dev-khoi

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Incorrect key prop usage in React lists causes subtle bugs like state mismatches, unnecessary re-renders, and components being destroyed and recreated. This Skill provides clear rules for choosing stable, unique keys so list rendering behaves predictably. ## Core Features & Use Cases - Key Selection Guidance: Explains why stable data IDs are preferred and when array index is acceptable. - Anti-Pattern Detection: Covers common mistakes such as using Math.random() during render, index keys on dynamic lists, and misusing useId() for keys. - ID Generation Strategy: Shows how to generate stable IDs once at data load time using nanoid when source data lacks identifiers. - Use Case: When a sorted or filtered todo list shows input values attached to the wrong rows, apply these rules to replace index keys with stable data IDs and fix the state mismatch. ## Quick Start Review my React list rendering code and fix any incorrect key prop usage following best practices.

Frequently Asked Questions about react-key-prop

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

FAQPage Schema
How do I choose the right key prop for React lists?▼

Use a unique, stable ID from your data, such as todo.id, as the key prop. Keys must be unique among siblings, stable across renders, and directly tied to the data item so React can track element identity during reconciliation.

When is it okay to use array index as key in React?▼

Index as key is acceptable only when the list is completely static: items are never added or removed except at the end, order never changes, and items have no internal state. For any dynamic list, index keys cause state mismatch bugs.

Why does using Math.random() as a React key break rendering?▼

Math.random() generates a new key on every render, so React treats every element as new and destroys and recreates all components each time. This loses component state and wastes rendering work. Generate IDs once when data loads instead.

Can I use React useId() to generate list keys?▼

No, useId() is designed for accessibility attributes like linking labels to inputs, not for list keys. It does not produce keys tied to data identity. Use IDs from your data or generate them once with nanoid when loading data.

Why does my React list show wrong state after sorting or filtering?▼

This happens when index is used as the key on a dynamic list. Index represents position, not data identity, so when order changes React reuses the wrong component instances. Switch to stable data IDs as keys to fix the mismatch.