Agent skill
react-patterns
React and Next.js development policies. Use when writing React components, hooks, or performance optimization. Do NOT use for Vue.js code -- use vue-patterns instead.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/react-patterns-cooldaemon-dotfiles
SKILL.md
React/Next.js Patterns
State Management Policies
Always Use Functional Updates
// GOOD
setCount(prev => prev + 1)
// BAD: Can be stale in async
setCount(count + 1)
Context Null Check Required
const context = useContext(MyContext)
if (!context) throw new Error('Must be used within Provider')
Conditional Rendering
// GOOD: Clear conditions
{isLoading && <Spinner />}
{error && <ErrorMessage error={error} />}
{data && <DataDisplay data={data} />}
// BAD: Ternary hell
{isLoading ? <Spinner /> : error ? <ErrorMessage /> : data ? <DataDisplay /> : null}
Performance Policies
Memoization Guidelines
| Technique | When to Use |
|---|---|
useMemo |
Expensive computations with stable deps |
useCallback |
Functions passed to memoized children |
React.memo |
Pure components with frequent parent re-renders |
Default: Let React Compiler handle memoization. Manual useMemo/useCallback/React.memo only when precise control over re-render boundaries is needed.
Code Splitting - Use for Heavy Components
const HeavyChart = lazy(() => import('./HeavyChart'))
<Suspense fallback={<Spinner />}>
<HeavyChart />
</Suspense>
Virtualization - Use for 100+ Items
Use @tanstack/react-virtual for long lists.
Accessibility Policies
Always Use useId for Form Labels
const hintId = useId()
<input aria-describedby={hintId} />
<p id={hintId}>Hint text</p>
Modal Focus Management Required
- Save previous focus on open
- Focus modal on open
- Restore focus on close
- Handle Escape key
Anti-Patterns
| Anti-Pattern | Correct Approach |
|---|---|
setCount(count + 1) in async |
Use functional update |
| Deeply nested ternaries | Use && or early returns |
| Inline object/array in deps | Extract to stable reference |
| Missing key in lists | Always provide unique key |
| useEffect for derived state | Use useMemo or compute inline |
Component Design Policies
Prefer Composition
Composition over configuration — components should be assembled, not configured via props.
// GOOD
<Card>
<CardHeader>Title</CardHeader>
<CardBody>Content</CardBody>
</Card>
// BAD: Props drilling
<Card header="Title" body="Content" footer="..." />
Compound Components for Related UI
Use Context to share state between related components (Tabs, Accordion, etc.).
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?