Agent skill

react-patterns

Modern React patterns and principles. Hooks, composition, performance, TypeScript best practices.

Stars 23,776
Forks 2,298

Install this agent skill to your Project

npx add-skill https://github.com/davila7/claude-code-templates/tree/main/cli-tool/components/skills/development/react-patterns

SKILL.md

React Patterns

Principles for building production-ready React applications.


1. Component Design Principles

Component Types

Type Use State
Server Data fetching, static None
Client Interactivity useState, effects
Presentational UI display Props only
Container Logic/state Heavy state

Design Rules

  • One responsibility per component
  • Props down, events up
  • Composition over inheritance
  • Prefer small, focused components

2. Hook Patterns

When to Extract Hooks

Pattern Extract When
useLocalStorage Same storage logic needed
useDebounce Multiple debounced values
useFetch Repeated fetch patterns
useForm Complex form state

Hook Rules

  • Hooks at top level only
  • Same order every render
  • Custom hooks start with "use"
  • Clean up effects on unmount

3. State Management Selection

Complexity Solution
Simple useState, useReducer
Shared local Context
Server state React Query, SWR
Complex global Zustand, Redux Toolkit

State Placement

Scope Where
Single component useState
Parent-child Lift state up
Subtree Context
App-wide Global store

4. React 19 Patterns

New Hooks

Hook Purpose
useActionState Form submission state
useOptimistic Optimistic UI updates
use Read resources in render

Compiler Benefits

  • Automatic memoization
  • Less manual useMemo/useCallback
  • Focus on pure components

5. Composition Patterns

Compound Components

  • Parent provides context
  • Children consume context
  • Flexible slot-based composition
  • Example: Tabs, Accordion, Dropdown

Render Props vs Hooks

Use Case Prefer
Reusable logic Custom hook
Render flexibility Render props
Cross-cutting Higher-order component

6. Performance Principles

When to Optimize

Signal Action
Slow renders Profile first
Large lists Virtualize
Expensive calc useMemo
Stable callbacks useCallback

Optimization Order

  1. Check if actually slow
  2. Profile with DevTools
  3. Identify bottleneck
  4. Apply targeted fix

7. Error Handling

Error Boundary Usage

Scope Placement
App-wide Root level
Feature Route/feature level
Component Around risky component

Error Recovery

  • Show fallback UI
  • Log error
  • Offer retry option
  • Preserve user data

8. TypeScript Patterns

Props Typing

Pattern Use
Interface Component props
Type Unions, complex
Generic Reusable components

Common Types

Need Type
Children ReactNode
Event handler MouseEventHandler
Ref RefObject<Element>

9. Testing Principles

Level Focus
Unit Pure functions, hooks
Integration Component behavior
E2E User flows

Test Priorities

  • User-visible behavior
  • Edge cases
  • Error states
  • Accessibility

10. Anti-Patterns

❌ Don't ✅ Do
Prop drilling deep Use context
Giant components Split smaller
useEffect for everything Server components
Premature optimization Profile first
Index as key Stable unique ID

Remember: React is about composition. Build small, combine thoughtfully.

Expand your agent's capabilities with these related and highly-rated skills.

davila7/claude-code-templates

verl-rl-training

Provides guidance for training LLMs with reinforcement learning using verl (Volcano Engine RL). Use when implementing RLHF, GRPO, PPO, or other RL algorithms for LLM post-training at scale with flexible infrastructure backends.

23,776 2,298
Explore
davila7/claude-code-templates

openrlhf-training

High-performance RLHF framework with Ray+vLLM acceleration. Use for PPO, GRPO, RLOO, DPO training of large models (7B-70B+). Built on Ray, vLLM, ZeRO-3. 2× faster than DeepSpeedChat with distributed architecture and GPU resource sharing.

23,776 2,298
Explore
davila7/claude-code-templates

gguf-quantization

GGUF format and llama.cpp quantization for efficient CPU/GPU inference. Use when deploying models on consumer hardware, Apple Silicon, or when needing flexible quantization from 2-8 bit without GPU requirements.

23,776 2,298
Explore
davila7/claude-code-templates

Claude Code Guide

Master guide for using Claude Code effectively. Includes configuration templates, prompting strategies "Thinking" keywords, debugging techniques, and best practices for interacting with the agent.

23,776 2,298
Explore
davila7/claude-code-templates

qdrant-vector-search

High-performance vector similarity search engine for RAG and semantic search. Use when building production RAG systems requiring fast nearest neighbor search, hybrid search with filtering, or scalable vector storage with Rust-powered performance.

23,776 2,298
Explore
davila7/claude-code-templates

behavioral-modes

AI operational modes (brainstorm, implement, debug, review, teach, ship, orchestrate). Use to adapt behavior based on task type.

23,776 2,298
Explore

Didn't find tool you were looking for?

Be as detailed as possible for better results