mcpField
R
react-patterns

react-patterns

github.com/shipshitdevDevelopment3989 installsUpdated 1d ago
Repository

About react-patterns

react-patterns is a skill for developers building React applications. It organizes guidance on components, hooks, state, performance, error handling, TypeScript, and testing into practical patterns.

Key features

  1. 01Choose component types and responsibilities
  2. 02Apply hook and state-management patterns
  3. 03Use React 19 hooks
  4. 04Compose interfaces with compound components
  5. 05Profile before optimizing performance
  6. 06Handle errors, types, and tests

Use cases

  1. 01Structuring components in a React feature
  2. 02Choosing state scope and storage approach
  3. 03Reviewing performance or error-recovery choices
  4. 04Planning component and user-flow tests

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/shipshitdev/skills --skill react-patterns

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

Bundled filesplugin.json

Details

From the project README

React Patterns

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.

When to Use

This skill is applicable to execute the workflow or actions described in the overview.

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.

Comments

Markdown supported