skills/coding/react-component-refactor/SKILL.md
Analyzes React component structure, identifies reusable units, and refactors large or messy components into clean, well-organized code. Strictly maintains 1:1 logic equivalence — only structure changes, never behavior. Should be used when the user wants to refactor a React component — splitting a monolith, reorganizing a messy file, or restructuring for better maintainability. Distinguished from react-component-extraction which extracts specific reusable pieces, this skill restructures the entire component.
npx skillsauth add ImaginerLabs/skill-manager react-component-refactorInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Analyze existing code structure, identify reusable logic, and refactor according to React best practices. Strictly preserve original logic intent — only optimize and split at the structure level.
The difference from react-component-extraction: extraction pulls out a specific piece for reuse; refactoring restructures the entire component for clarity and maintainability. Think of extraction as surgery, refactoring as renovation.
1. Confirm refactoring scope and output directory
2. Analyze code structure (identify reusable units)
3. Design refactoring plan (seek confirmation)
4. Execute refactoring
5. Verify logic equivalence
| Info | Description | | --------------------- | --------------------------------------------------------------------------- | | Refactoring scope | File path or code snippet specified by user | | Output directory | Where refactored files go (do not change without permission) | | Refactoring goal | Expected outcome (e.g., split sub-components, extract Hooks, full refactor) |
Analysis dimensions:
├── Component scale: total lines, JSX nesting depth
├── Responsibility identification: what different responsibilities does this component handle
├── Duplicate logic: similar JSX structures or logic patterns
├── State distribution: is state distribution reasonable
├── Side effects: number and clarity of useEffect responsibilities
└── Reusable units: what can become independent components or Hooks
| Condition | Example | | ---------------------------------------------------------------- | ----------------------------------------------------------- | | JSX structure exceeds 30 lines with relatively independent logic | Complex form sections, data display cards | | Same structure appears 2+ times in the same file | Similar list items, repeated button groups | | Has independent interaction state (expand/collapse) | Collapsible panels, dropdown menus, modal triggers | | Can be used independently from current context | Generic Loading state, empty state placeholder, error block |
| Condition | Example | | ---------------------------------------------------------- | ------------------------------------------------- | | Contains 2+ related state values + useEffect | Data fetching logic (loading + data + error) | | Same Hook combination used in multiple places | Pagination logic, form validation logic | | Side effect logic not directly tied to UI rendering | Event listeners, timers, WebSocket connections | | High complexity logic affecting main component readability | Complex filter/sort logic, permission check logic |
Present the plan to the user for confirmation before executing:
Refactoring plan: [original filename]
Original file: src/pages/Order/index.tsx (320 lines)
Split plan:
├── 📦 OrderHeader.tsx → Extract order header info display (original L12-L58)
├── 📦 OrderItemList.tsx → Extract order item list (original L60-L130)
├── 🪝 useOrderDetail.ts → Extract order data fetching logic
└── 📄 index.tsx → Refactored main file (keep core orchestration logic)
Output directory: src/pages/Order/components/
Confirm execution?
Each component file organized in this order: external imports → internal imports → type definitions → component implementation → exports
Hook returns use object format (when > 2 return values), including standard data / loading / error / refetch fields.
| Prohibited change | Why | | ------------------------ | ----------------------------------------------------------------- | | Business logic | Conditions, calculations, data processing must remain identical | | Side effect timing | useEffect trigger timing and dependencies must not change | | State initial values | All state initial values must match original code | | Event handling logic | Event callback execution logic must not be simplified or modified | | Render conditions | All conditional rendering logic must remain consistent | | Props interface | Exposed Props signature must not have breaking changes |
If original code has obvious bugs or anti-patterns, do not fix them — annotate and inform the user:
// ⚠️ Note: original code uses index as key here, consider changing to item.id later
{items.map((item, index) => <Item key={index} data={item} />)}
useCallbackuseMemoReact.memo## React Component Refactoring Report
### Refactoring Overview
- **Original file**: `[original file path]` (X lines)
- **Output directory**: `[user-specified directory]`
- **Split file count**: X
### Split Results
| File | Type | Original lines | Description |
| -------------- | -------------------- | -------------- | -------------------------- |
| ComponentA.tsx | Sub-component | L12~L58 | Responsibility description |
| useXxx.ts | Custom Hook | L60~L90 | Responsibility description |
| index.tsx | Refactored main file | — | Core orchestration logic |
### Logic Equivalence Verification
- [ ] Conditional rendering: ✅ Matches original
- [ ] List rendering: ✅ Key values and data source match
- [ ] Event binding: ✅ Trigger conditions and execution logic unchanged
- [ ] Side effect dependencies: ✅ useEffect dependency arrays unchanged
- [ ] State flow: ✅ State update logic completely identical
### Original Code Issues Found (annotated, not fixed)
- If none: ✅ No obvious bugs or anti-patterns found
development
Use this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation.
devops
Create a new implementation plan file for new features, refactoring existing code or upgrading packages, design, architecture or infrastructure.
tools
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
documentation
Generates standardized porting documentation from completed feature changes. Analyzes commit diffs or file contents, extracts change intent, and outputs Markdown documentation for cross-team understanding. Should be used when the user needs to document a change for cross-team or cross-project consumption. Distinguished from cross-branch-fix-porter which actively re-implements fixes, this skill documents changes.