React refactor

From pproenca/dot-skills · View interactive version

React refactor is an AI agent skill from the GitHub repository pproenca/dot-skills. 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 over

How to use this skill

Skill file

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

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:

Common mistakes — avoid these anti-patterns:

Table of Contents

  1. Component Architecture — CRITICAL
  1. State Architecture — CRITICAL
  1. Hook Patterns — HIGH
  1. Component Decomposition — HIGH
  1. Coupling & Cohesion — MEDIUM
  1. Data & Side Effects — MEDIUM
  1. Refactoring Safety — LOW-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

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.