.config/opencode/skills/react-key-prop/SKILL.md
Guides proper usage of the key prop in React lists. Use this skill when rendering lists, mapping arrays to components, or troubleshooting list-related state bugs.
npx skillsauth add klen/dotfiles react-key-propInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use stable, unique IDs from your data. Never use array index for dynamic lists.
The key prop provides stable identity to list elements during React's reconciliation process.
Always use unique, stable identifiers directly from your data:
// ✅ Correct
{todos.map((todo) => (
<li key={todo.id}>{todo.text}</li>
))}
Ideal keys are:
When data lacks IDs, create them once when receiving data:
import { nanoid } from 'nanoid';
useEffect(() => {
fetch('/api/items')
.then(res => res.json())
.then(data => {
const itemsWithIds = data.map(item => ({
...item,
_tempId: nanoid() // Stable ID generated once
}));
setItems(itemsWithIds);
});
}, []);
Index as key is acceptable ONLY when ALL conditions are met:
// ❌ WRONG: Creates new key every render
{items.map(item => (
<li key={Math.random()}>{item.name}</li>
))}
This forces React to destroy and recreate all components on every render.
// ❌ WRONG for dynamic lists
{items.map((item, index) => (
<li key={index}>{item.name}</li>
))}
Index fails when:
The bug: Index represents position, not data identity. When positions change but indexes stay the same, React incorrectly "mutates" existing components instead of creating new ones, causing state mismatch.
useId() for List KeysReact's useId() hook is for accessibility (linking labels to inputs),
not for generating list keys.
key when rendering listsid from your datananoid/uuid)key during render (Math.random(), Date.now())index as key for dynamic listsuseId() for list keystools
Anti-patterns and mistakes to avoid as a product manager. Use when evaluating leadership behaviors, improving team dynamics, reflecting on management practices, or onboarding new product managers.
development
Guides proper usage of TypeScript's satisfies operator vs type annotations. Use this skill when deciding between type annotations (colon) and satisfies, validating object shapes while preserving literal types, or troubleshooting type inference issues.
development
Guides when to use interface vs type in TypeScript. Use this skill when defining object types, extending types, or choosing between interface and type aliases.
development
Guides TypeScript best practices for type safety, code organization, and maintainability. Use this skill when configuring TypeScript projects, deciding on typing strategies, writing async code, or reviewing TypeScript code quality.