react-refactoring
Installation
SKILL.md
React Component Refactoring Skill
This skill provides a systematic approach to refactoring complex React components. The goal is to transform monolithic, tangled code into clean, modular, and maintainable structures, specifically targeting code length and structure issues.
When to Use
Trigger this skill when you encounter:
- Excessive Length: File size exceeds 200-300 lines.
- Tangled Logic: Business logic, API calls, and state management are mixed directly with UI rendering.
- Complex State: Multiple
useStateoruseEffectcalls make the flow hard to follow. - Deep Nesting: Render methods contain deeply nested conditionals or loops.
- Cognitive Overload: The component is difficult to read or understand quickly.
Core Principles
- Single Responsibility: Each component or hook should do one thing well.
- Separation of Concerns: Strictly separate View (JSX/UI) from Logic (State/Effects/Handlers).
- Composition: Build complex interfaces by composing smaller, focused sub-components.
- Colocation: Keep related styles, types, and helpers close to where they are used.