mcpField
R
react-patterns

react-patterns

github.com/majesticlabs-devDevelopment5048 installsUpdated 7w ago
Repository

About react-patterns

A guidance skill for developers building modern React interfaces, covering composition, hooks, state management, performance, and accessibility. It focuses on reusable patterns and decisions rather than executing tasks.

Key features

  1. 01Component composition patterns
  2. 02Custom hook guidance
  3. 03State management choices
  4. 04Performance and code splitting
  5. 05Error handling and accessibility

Use cases

  1. 01Designing reusable compound components
  2. 02Writing hooks for forms and data fetching
  3. 03Choosing state approaches for interfaces
  4. 04Optimizing large components and interactions

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/majesticlabs-dev/majestic-marketplace --skill react-patterns

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

Bundled filesreferences/examples.md

Details

From the project README

React Patterns

Expert guidance for implementing modern React patterns using hooks, component composition, state management, and concurrent features.

Core Philosophy

PriorityDescription
Component CompositionBuild complex UIs from simple, reusable pieces
Separation of ConcernsBusiness logic in hooks, presentation in components
Explicit over ImplicitClear data flow and state management
PerformanceMinimize re-renders, optimize heavy computations
AccessibilityBuild inclusive, keyboard-navigable interfaces

Pattern Categories

Component Composition Patterns
PatternUse CaseExample
Compound ComponentsFlexible component APIs with shared contextAccordion, Tabs, Menu
Render PropsShare logic between componentsMouseTracker, Scroll position
Higher-Order ComponentsWrap components to add functionalitywithAuth, withLoading

See references/examples.md for full code examples.

Custom Hooks Patterns
HookPurpose
useApiData fetching with loading/error states
useFormForm state management with validation
useDebounceDebounce rapidly changing values
usePreviousAccess previous value of state/prop
useLocalStoragePersist state to localStorage

See references/examples.md for implementations.

State Management Patterns
TypeWhen to UseExamples
useStateSimple UI stateToggles, form inputs, pagination
useReducerComplex state logicMulti-step forms, shopping cart
ContextTheme, auth, app-wide settingsUser session, feature flags
URL StateShareable/bookmarkable stateFilters, search params, tabs
Server StateAPI data (React Query/SWR)User profiles, product catalogs
Global StoreCross-feature coordinationZustand/Redux for complex apps

Context + useReducer Pattern: Best for complex state with multiple actions that need to be shared across components. See references/examples.md.

Performance Optimization

When to Use Memoization
ToolUse When
useMemoExpensive calculations (sorting, filtering large arrays)
useCallbackFunctions passed to memoized children or used in deps
memoPure components that re-render often with same props
Code Splitting Strategy
LevelImplementation
Route-levellazy(() => import('./pages/Dashboard'))
Component-levelHeavy components like charts, editors
ConditionalFeatures behind feature flags

Always wrap lazy components in <Suspense> with appropriate fallback.

Error Handling

StrategyScope
Error BoundariesComponent tree errors (class components)
try/catchAsync operations, event handlers
React Query onErrorAPI errors with automatic retry

Error Boundary Placement: App-level for fatal errors, feature-level for graceful degradation.

Accessibility Patterns

RequirementImplementation
Focus ManagementReturn focus to trigger on modal close
Keyboard NavigationSupport Tab, Enter, Escape in interactive elements
ARIA LabelsIcon buttons, form inputs without visible labels
Semantic HTMLUse <nav>, <main>, <button> appropriately

See references/examples.md for accessible modal implementation.

Best Practices Checklist

  1. Extract custom hooks when logic is reused or complex (>20 lines)
  2. Use compound components for flexible component APIs
  3. Memoize expensive computations and callbacks passed to memoized children
  4. Code split routes and heavy components
  5. Handle errors with error boundaries at appropriate levels
  6. Manage focus in modals and dynamic content
  7. Use semantic HTML and ARIA labels for accessibility
  8. Test hooks in isolation from components
  9. Keep components small (< 200 lines)
  10. Colocate state with its usage

Comments

Markdown supported