Marketplace

react-patterns

Expert guidance on modern React patterns including hooks, composition, state management, and concurrent features. Use when implementing React components or refactoring existing code.

allowed_tools: Read, Write, Edit, Grep, Glob, Bash, WebSearch

$ Installer

git clone https://github.com/majesticlabs-dev/majestic-marketplace /tmp/majestic-marketplace && cp -r /tmp/majestic-marketplace/plugins/majestic-react/skills/react-patterns ~/.claude/skills/majestic-marketplace

// tip: Run this command in your terminal to install the skill


name: react-patterns description: Expert guidance on modern React patterns including hooks, composition, state management, and concurrent features. Use when implementing React components or refactoring existing code. allowed-tools: Read, Write, Edit, Grep, Glob, Bash, WebSearch

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 resources/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 resources/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 resources/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 resources/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

Repository

majesticlabs-dev
majesticlabs-dev
Author
majesticlabs-dev/majestic-marketplace/plugins/majestic-react/skills/react-patterns
13
Stars
0
Forks
Updated1w ago
Added1w ago