Agent Skills: React Refactor Best Practices

Architectural refactoring guide for React applications covering component architecture, state architecture, hook patterns, component decomposition, coupling and cohesion, data flow, and refactoring safety. Use when refactoring React codebases, reviewing PRs for architectural issues, decomposing oversized components, or improving module boundaries. Does NOT cover React 19 API usage (see react skill) or performance optimization (see react-optimise skill).

UncategorizedID: pproenca/dot-skills/react-refactor

Install this agent skill to your local

pnpm dlx add-skill https://github.com/pproenca/dot-skills/tree/HEAD/skills/.experimental/react-refactor

Skill Files

Browse the full folder contents for react-refactor.

Download Skill

Loading file tree…

skills/.experimental/react-refactor/SKILL.md

Skill Metadata

Name
react-refactor
Description
Architectural refactoring guide for React applications covering component architecture, state architecture, hook patterns, component decomposition, coupling and cohesion, data flow, and refactoring safety. Use when refactoring React codebases, reviewing PRs for architectural issues, decomposing oversized components, or improving module boundaries. Does NOT cover React 19 API usage (see react skill) or performance optimization (see react-optimise skill).

React Refactor Best Practices

Architectural refactoring guide for React applications. Contains 40 rules across 7 categories, prioritized by impact from critical (component and state architecture) to incremental (refactoring safety).

When to Apply

  • Refactoring existing React codebases or planning large-scale restructuring
  • Reviewing PRs for architectural issues and code smells
  • Decomposing oversized components into focused units
  • Extracting reusable hooks from component logic
  • Improving testability of React code
  • Reducing coupling between feature modules

Rule Categories

| Category | Impact | Rules | Key Topics | |----------|--------|-------|------------| | Component Architecture | CRITICAL | 8 | Compound components, headless pattern, composition over props, client boundaries | | State Architecture | CRITICAL | 7 | Colocation, state machines, URL state, derived values | | Hook Patterns | HIGH | 6 | Single responsibility, naming, dependency stability, composition | | Component Decomposition | HIGH | 6 | Scroll test, extraction by change reason, view/logic separation | | Coupling & Cohesion | MEDIUM | 4 | Dependency injection, circular deps, stable imports, barrel-free | | Data & Side Effects | MEDIUM | 4 | Server-first fetch, TanStack Query, error boundaries | | Refactoring Safety | LOW-MEDIUM | 5 | Characterization tests, behavior testing, integration tests |

Quick Reference

Critical patterns — get these right first:

  • Use compound components instead of props explosion
  • Colocate state with the components that use it
  • Use state machines for complex UI workflows
  • Separate container logic from presentational components

Common mistakes — avoid these anti-patterns:

  • Lifting state to App when only one component reads it
  • Using context for rapidly-changing values
  • Monolithic hooks that fetch + transform + cache
  • Testing implementation details instead of behavior

Table of Contents

  1. Component ArchitectureCRITICAL
  2. State ArchitectureCRITICAL
  3. Hook PatternsHIGH
  4. Component DecompositionHIGH
  5. Coupling & CohesionMEDIUM
  6. Data & Side EffectsMEDIUM
  7. Refactoring SafetyLOW-MEDIUM

References

  1. https://react.dev
  2. https://react.dev/learn/thinking-in-react
  3. https://kentcdodds.com/blog/application-state-management-with-react
  4. https://testing-library.com/docs/guiding-principles
  5. https://patterns.dev

Related Skills

  • For React 19 API best practices, see react skill
  • For application performance optimization, see react-optimise skill
  • For client-side form handling, see react-hook-form skill