mcpField
R
react-patterns

react-patterns

github.com/davila7Development33.0k502 installsUpdated today
Repository

About react-patterns

A pattern guide for React developers covering component design, hooks, state management, performance, error handling, TypeScript, and testing. It also outlines React 19 hooks and choices based on application complexity.

Key features

  1. 01Component design and composition patterns
  2. 02Custom hooks and state management
  3. 03React 19 hook patterns
  4. 04Performance profiling and targeted optimization
  5. 05Error handling and recovery
  6. 06TypeScript and testing principles

Use cases

  1. 01Plan component responsibilities and state scope
  2. 02Choose a state management approach
  3. 03Diagnose React rendering performance
  4. 04Design error handling and testing strategies

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/davila7/claude-code-templates --skill react-patterns

After installing, type/react-patternsin Claude Code to confirm it loaded.

Details

From the project README

React Patterns

Principles for building production-ready React applications.


1. Component Design Principles

Component Types
TypeUseState
ServerData fetching, staticNone
ClientInteractivityuseState, effects
PresentationalUI displayProps only
ContainerLogic/stateHeavy 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
PatternExtract When
useLocalStorageSame storage logic needed
useDebounceMultiple debounced values
useFetchRepeated fetch patterns
useFormComplex 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

ComplexitySolution
SimpleuseState, useReducer
Shared localContext
Server stateReact Query, SWR
Complex globalZustand, Redux Toolkit
State Placement
ScopeWhere
Single componentuseState
Parent-childLift state up
SubtreeContext
App-wideGlobal store

4. React 19 Patterns

New Hooks
HookPurpose
useActionStateForm submission state
useOptimisticOptimistic UI updates
useRead 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 CasePrefer
Reusable logicCustom hook
Render flexibilityRender props
Cross-cuttingHigher-order component

6. Performance Principles

When to Optimize
SignalAction
Slow rendersProfile first
Large listsVirtualize
Expensive calcuseMemo
Stable callbacksuseCallback
Optimization Order
  1. Check if actually slow
  2. Profile with DevTools
  3. Identify bottleneck
  4. Apply targeted fix

7. Error Handling

Error Boundary Usage
ScopePlacement
App-wideRoot level
FeatureRoute/feature level
ComponentAround risky component
Error Recovery
  • Show fallback UI
  • Log error
  • Offer retry option
  • Preserve user data

8. TypeScript Patterns

Props Typing
PatternUse
InterfaceComponent props
TypeUnions, complex
GenericReusable components
Common Types
NeedType
ChildrenReactNode
Event handlerMouseEventHandler
RefRefObject

9. Testing Principles

LevelFocus
UnitPure functions, hooks
IntegrationComponent behavior
E2EUser flows
Test Priorities
  • User-visible behavior
  • Edge cases
  • Error states
  • Accessibility

10. Anti-Patterns

❌ Don't✅ Do
Prop drilling deepUse context
Giant componentsSplit smaller
useEffect for everythingServer components
Premature optimizationProfile first
Index as keyStable unique ID

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

Comments

Markdown supported