Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsBlogPro
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges
  • Chrome Extension
  • Skill Manager

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Component Refactoring

ASecurity

Refactor high-complexity React components. Use when complexity metrics are high or to split monolithic UI.

2 stars
0 votes
0 copies
0 views
Added 9/27/2026
code-qualitygoreactrefactoringapi

Works with

api

Security Analysis

A100/100

Scanned 9/27/2026

$npx -y skills add David-Li0406/meta-skill-evloving --skill component-refactoring --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Component Refactoring?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Component Refactoring
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/david-li0406-component-refactoring/badge)](https://www.skillsdirectory.com/skills/david-li0406-component-refactoring)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
Files
SKILL.md
---
name: component-refactoring
description: Refactor high-complexity React components. Use when complexity metrics are high or to split monolithic UI.
---

# Component Refactoring Skill

Refactor high-complexity React components with proven patterns and workflows.

**Complexity Threshold**: Components with **cyclomatic complexity > 50** or **line count > 300** should be candidates for refactoring.

**Use When**:
- `pnpm analyze-component` shows high complexity.
- Users ask for "code splitting", "hook extraction", or "cleanup".
- A component file exceeds 300 lines of code.

## Core Refactoring Patterns

### 1. Extract Custom Hooks
**Goal**: Separate UI from State/Logic.

**Before**:
```tsx
function UserList() {
  const [users, setUsers] = useState([]);
  const [loading, setLoading] = useState(false);

  useEffect(() => {
    setLoading(true);
    fetch('/api/users').then(data => {
      setUsers(data);
      setLoading(false);
    });
  }, []);

  if (loading) return <Spinner />;
  return <ul>{users.map(u => <li key={u.id}>{u.name}</li>)}</ul>;
}
```

**After**:
```tsx
// hooks/useUsers.ts
function useUsers() {
  return useQuery({ queryKey: ['users'], queryFn: fetchUsers });
}

// UserList.tsx
function UserList() {
  const { data: users, isLoading } = useUsers();
  if (isLoading) return <Spinner />;
  return <UserListView users={users} />;
}
```

### 2. Extract Sub-Components
**Goal**: Break down monolithic JSX.

**Before**:
```tsx
function Dashboard() {
  return (
    <div>
      <header>...</header>
      <aside>...</aside>
      <main>
        <section className="stats">...</section>
        <section className="feed">...</section>
      </main>
    </div>
  );
}
```

**After**:
```tsx
function Dashboard() {
  return (
    <Layout>
      <DashboardHeader />
      <DashboardSidebar />
      <DashboardContent>
        <StatsWidget />
        <ActivityFeed />
      </DashboardContent>
    </Layout>
  );
}
```

### 3. Simplify Conditional Logic
**Goal**: Reduce nesting and `if/else` checks implementation details.

- Use **Lookup Tables** (Maps/Objects) instead of Switch/If-Else chains.
- Use **Guard Clauses** (Early Returns) to avoid deep nesting.

### 4. Extract Modal Management
**Goal**: Centralize modal state and logic.

- Move modal definitions to a generic `<ModalManager />` or context if reused globally.
- Keep the `isOpen` state locally if specific to a single component, but extract the Modal content to a separate file.

## Workflow

1. **Analyze**: Run complexity analysis or review the file manually.
2. **Plan**: Identify seam lines (Logic vs UI, Section vs Section).
3. **Extract**: Create new files for hooks or components.
4. **Integrate**: Replace original code with imports.
5. **Verify**: Ensure functionality remains identical and tests pass.

Attribution

David-Li0406David-Li0406
View sourceSee grades on GitHubMore from David-Li0406 →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Caveman Review

Ultra-compressed code review comments. Cuts noise from PR feedback while preserving the actionable signal. Each comment is one line: location, problem, fix. Use when user says "review this PR", "code review", "review the diff", "/review", or invokes /caveman-review. Auto-triggers when reviewing pull requests.

1100021 votes

Caveman Commit

Ultra-compressed commit message generator. Cuts noise from commit messages while preserving intent and reasoning. Conventional Commits format. Subject ≤50 chars, body only when "why" isn't obvious. Use when user says "write a commit", "commit message", "generate commit", "/commit", or invokes /caveman-commit. Auto-triggers when staging changes.

1100021 votes

Springboot Verification

Verification loop for Spring Boot projects: build, static analysis, tests with coverage, security scans, and diff review before release or PR.

2456590 votes

Verification Loop

一个全面的 Claude Code 会话验证系统。

2456590 votes

Django Verification

Verification loop for Django projects: migrations, linting, tests with coverage, security scans, and deployment readiness checks before release or PR.

2456590 votes
View all in code-quality →