Agent skill
react-patterns
React best practices and anti-patterns reference. Use when writing React components, reviewing code for anti-patterns, debugging useEffect issues, optimizing performance, or deciding between state vs derived values. Covers Effects, state design, component patterns, performance, and event handling.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/react-patterns-iamhenry-ai-project-starter-k
SKILL.md
React Patterns
Overview
Decision-driven guidance for writing idiomatic React. Focus on avoiding common anti-patterns and choosing the right tool for each job.
Quick Decision Trees
Should This Be a useEffect?
Is this synchronizing with an EXTERNAL system?
├─ YES (DOM, network, third-party widget) → useEffect
└─ NO
├─ Caused by USER ACTION? → Event handler
├─ Can be CALCULATED from state/props? → Render-time calculation
└─ Runs because component DISPLAYED? → useEffect
Should This Be State?
Can it be computed from existing props/state?
├─ YES → Derive it (const x = ...)
└─ NO
├─ Does it change over time? → useState
└─ NO → Regular variable or prop
Should I Memoize This?
Is the calculation expensive (>1ms)?
├─ NO → Don't memoize
└─ YES
├─ Used in render? → useMemo
└─ Passed to child as prop? → Consider useMemo
Anti-Pattern Quick Reference
| BAD | GOOD | Reference |
|---|---|---|
| Derived state in useEffect | Calculate during render | references/effects.md |
| useEffect for event logic | Put in event handler | references/effects.md |
| useEffect to reset state on prop | Use React key prop |
references/effects.md |
| Effect chains (A→B→C) | Calculate in single handler | references/effects.md |
| Notify parent via useEffect | Call in same event handler | references/effects.md |
| Store full object when ID suffices | Store ID, derive object | references/state.md |
| Prop drilling 5+ levels | Composition or context | references/components.md |
| useMemo/useCallback everywhere | Only when measurably needed | references/performance.md |
| Inline handlers causing re-renders | useCallback IF measured issue | references/performance.md |
| Logic in onClick directly | Extract to named handler | references/events.md |
When to Load References
Load the specific reference file when working on that area:
- Effects issues:
Read(.claude/skills/react-patterns/references/effects.md) - State structure:
Read(.claude/skills/react-patterns/references/state.md) - Component design:
Read(.claude/skills/react-patterns/references/components.md) - Performance:
Read(.claude/skills/react-patterns/references/performance.md) - Event handling:
Read(.claude/skills/react-patterns/references/events.md)
Core Principles
- Effects are escape hatches - Only for external system sync
- Derive, don't sync - If computable, compute it
- State should be minimal - Store IDs not objects, derive the rest
- Measure before optimizing - No premature useMemo/useCallback
- Colocate related logic - Keep cause and effect together
- Data flows down - Avoid passing data up via Effects
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?