react-refactor

Extract hooks and migrate React state to useReducer in TypeScript projects.

Updated Nov 16, 2025
One-click install
npx skills add https://github.com/aaronjullger-lgtm/PANaCEa --skill react-refactor-aaronjullger-lgtm
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: react-refactor
Source: https://github.com/aaronjullger-lgtm/PANaCEa/tree/main/.claude/skills/react-refactor
Command: npx skills add https://github.com/aaronjullger-lgtm/PANaCEa --skill react-refactor-aaronjullger-lgtm

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Large React components accumulate state, handlers, effects, and JSX over time. The refactoring process is surgical: identify what can be extracted, extract it with zero behavioral change, then verify. Resist the urge to "improve" logic during extraction — that's a separate step. Refactoring and feature changes in the same pass create bugs that are hard to bisect.

Core Features & Use Cases

  • State consolidation: migrate many useState calls into a single useReducer-based state management structure with stable setters that preserve existing call patterns.
  • Hook extraction: group related logic into custom hooks to reduce complexity and improve reusability.
  • JSX restructuring: refactor layouts to improve readability and reduce re-renders without altering UI behavior.
  • Migration guidance: provide a drop-in API and documentation to ensure a zero-diff upgrade path for existing components.

Quick Start

Identify a large component and apply a safe refactor by extracting hooks and migrating state to useReducer without changing behavior.

Frequently Asked Questions about react-refactor

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor a large React component without changing its behavior?

Refactor large React components by surgically extracting hooks and migrating useState to useReducer to consolidate state. This behavior-preserving approach separates structural reorganization from logic changes, ensuring a zero-diff upgrade path for existing TypeScript components.

When should I migrate multiple useState calls to useReducer in React?

Migrate useState calls to useReducer when a React component accumulates many state variables and exceeds a few hundred lines. Consolidating state into a single useReducer structure with stable setters reduces complexity and improves reusability without altering existing call patterns.

What is the best way to extract custom hooks from a massive React component?

Extract custom hooks by grouping related logic, state, handlers, and effects from large React components. This reduces component complexity and improves reusability while delivering a drop-in hook-based pattern that preserves the original UI behavior.

Does this React refactoring approach work with TypeScript and React 19?

Yes, this refactoring approach applies specifically to TypeScript and React 19 projects. It targets large components with many useState usages, providing migration guidance and a drop-in API to ensure zero-diff upgrades in TypeScript environments.

Why should I avoid improving logic while extracting hooks from React components?

Avoid improving logic during hook extraction because combining refactoring and feature changes creates bugs that are hard to bisect. The process requires identifying extractable logic, extracting it with zero behavioral change, then verifying separately.

Can I reduce re-renders by restructuring JSX in large React components?

Restructuring JSX layouts in large React components improves readability and reduces re-renders without altering UI behavior. This surgical refactoring approach focuses on layout reorganization while maintaining a zero-diff upgrade path for existing components.