Agent skill

Component Refactoring

by PageAI-Pro in PageAI-Pro/ralph-loop

Refactor high-complexity React components in frontend. An agent skill from PageAI-Pro/ralph-loop.

MITAuto-check passedDevelopment

Install Component Refactoring

skills CLI
$ npx skills add PageAI-Pro/ralph-loop --skill component-refactoring -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install PageAI-Pro/ralph-loop component-refactoring --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/PageAI-Pro/ralph-loop.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agent/skills/component-refactoring .claude/skills/component-refactoring && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
component-refactoring
GitHub stars
311
Token cost
~1.8k tokens
SKILL.md length
189 words
Files
4 (incl. references)
Skills in repo
4
Repo updated
First seen
Licence
MIT

At a glance

Refactor high-complexity React components in frontend. An agent skill from PageAI-Pro/ralph-loop.

  • The user asks for code splitting
  • SKILL.md covers Core Refactoring Patterns, Common Mistakes to Avoid and References
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md
  • Hook extraction

What it does

Component Refactoring is an agent skill from PageAI-Pro/ralph-loop. Refactor high-complexity React components in frontend. Use when the user asks for code splitting, hook extraction, or complexity reduction, or when you come across a component that is too complex to understand and refactor it.

Its SKILL.md is about 1.8k tokens, which your agent loads only when the skill is triggered. The skill folder holds 4 other files, including reference files (for example `references/complexity-patterns.md`, `references/component-splitting.md` and `references/hook-extraction.md`).

It sits in Development, covering Refactoring and React components. The repository describes itself as: A long-running AI agent loop. Ralph automates software development tasks by iteratively working through a task list until completion. The licence is MIT.

When your agent uses it

  • The user asks for code splitting
  • Hook extraction
  • Complexity reduction
  • You come across a component that is too complex to understand and refactor it

Example prompts

  • “/component-refactoring”

What it can do on your machine

Read from SKILL.md and the folder at commit eba65eb. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are typescript).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Component Refactoring loads about 1.8k tokens when it runs, and up to ~9.4k if it reads all its reference files. Until then it costs about 62 tokens; SKILL.md has 189 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~62
When it runs · the whole SKILL.md, loaded when a task matches
~1.8k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~9.4k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from PageAI-Pro/ralph-loop at commit eba65eb, republished under its MIT licence (© PageAI-Pro). 189 words, ~1,785 tokens.

Download SKILL.mdSave it as .claude/skills/component-refactoring/SKILL.md (or your agent's skills folder). This skill also uses 3 other files; get the full folder from GitHub.
name
component-refactoring
description
Refactor high-complexity React components in frontend. Use when the user asks for code splitting, hook extraction, or complexity reduction, or when you come across a component that is too complex to understand and refactor it.

Component Refactoring Skill

Refactor high-complexity React components with the patterns and workflow below.

Core Refactoring Patterns

Pattern 1: Extract Custom Hooks

When: Component has complex state management, multiple useState/useEffect, or business logic mixed with UI.

Dify Convention: Place hooks in a hooks/ subdirectory or alongside the component as use-<feature>.ts.

typescript
// ❌ Before: Complex state logic in component
const Configuration: FC = () => {
  const [modelConfig, setModelConfig] = useState<ModelConfig>(...)
  const [datasetConfigs, setDatasetConfigs] = useState<DatasetConfigs>(...)
  const [completionParams, setCompletionParams] = useState<FormValue>({})

  // 50+ lines of state management logic...

  return <div>...</div>
}

// ✅ After: Extract to custom hook
// hooks/use-model-config.ts
export const useModelConfig = (appId: string) => {
  const [modelConfig, setModelConfig] = useState<ModelConfig>(...)
  const [completionParams, setCompletionParams] = useState<FormValue>({})

  // Related state management logic here

  return { modelConfig, setModelConfig, completionParams, setCompletionParams }
}

// Component becomes cleaner
const Configuration: FC = () => {
  const { modelConfig, setModelConfig } = useModelConfig(appId)
  return <div>...</div>
}
Pattern 2: Extract Sub-Components

When: Single component has multiple UI sections, conditional rendering blocks, or repeated patterns.

typescript
// ❌ Before: Monolithic JSX with multiple sections
const AppInfo = () => {
  return (
    <div>
      {/* 100 lines of header UI */}
      {/* 100 lines of operations UI */}
      {/* 100 lines of modals */}
    </div>
  )
}

// ✅ After: Split into focused components
// app-info/
//   ├── index.tsx           (orchestration only)
//   ├── app-header.tsx      (header UI)
//   ├── app-operations.tsx  (operations UI)
//   └── app-modals.tsx      (modal management)

const AppInfo = () => {
  const { showModal, setShowModal } = useAppInfoModals()

  return (
    <div>
      <AppHeader appDetail={appDetail} />
      <AppOperations onAction={handleAction} />
      <AppModals show={showModal} onClose={() => setShowModal(null)} />
    </div>
  )
}
Pattern 3: Simplify Conditional Logic

When: Deep nesting (> 3 levels), complex ternaries, or multiple if/else chains.

typescript
// ❌ Before: Deeply nested conditionals
const Template = useMemo(() => {
  if (appDetail?.mode === AppModeEnum.CHAT) {
    switch (locale) {
      case LanguagesSupported[1]:
        return <TemplateChatZh />
      case LanguagesSupported[7]:
        return <TemplateChatJa />
      default:
        return <TemplateChatEn />
    }
  }
  if (appDetail?.mode === AppModeEnum.ADVANCED_CHAT) {
    // Another 15 lines...
  }
  // More conditions...
}, [appDetail, locale])

// ✅ After: Use lookup tables + early returns
const TEMPLATE_MAP = {
  [AppModeEnum.CHAT]: {
    [LanguagesSupported[1]]: TemplateChatZh,
    [LanguagesSupported[7]]: TemplateChatJa,
    default: TemplateChatEn,
  },
  [AppModeEnum.ADVANCED_CHAT]: {
    [LanguagesSupported[1]]: TemplateAdvancedChatZh,
    // ...
  },
}

const Template = useMemo(() => {
  const modeTemplates = TEMPLATE_MAP[appDetail?.mode]
  if (!modeTemplates) return null

  const TemplateComponent = modeTemplates[locale] || modeTemplates.default
  return <TemplateComponent appDetail={appDetail} />
}, [appDetail, locale])
Pattern 4: Extract API/Data Logic

When: Component directly handles API calls, data transformation, or complex async operations.

typescript
// ❌ Before: API logic in component
const MCPServiceCard = () => {
  const [basicAppConfig, setBasicAppConfig] = useState({})

  useEffect(() => {
    if (isBasicApp && appId) {
      (async () => {
        const res = await fetchAppDetail({ url: '/apps', id: appId })
        setBasicAppConfig(res?.model_config || {})
      })()
    }
  }, [appId, isBasicApp])

  // More API-related logic...
}

// ✅ After: Extract to data hook using React Query
// use-app-config.ts
import { useQuery } from '@tanstack/react-query'
import { get } from '@/service/base'

const NAME_SPACE = 'appConfig'

export const useAppConfig = (appId: string, isBasicApp: boolean) => {
  return useQuery({
    enabled: isBasicApp && !!appId,
    queryKey: [NAME_SPACE, 'detail', appId],
    queryFn: () => get<AppDetailResponse>(`/apps/${appId}`),
    select: data => data?.model_config || {},
  })
}

// Component becomes cleaner
const MCPServiceCard = () => {
  const { data: config, isLoading } = useAppConfig(appId, isBasicApp)
  // UI only
}

React Query Best Practices:

  • Define NAME_SPACE for query key organization
  • Use enabled option for conditional fetching
  • Use select for data transformation
  • Export invalidation hooks: useInvalidXxx
Pattern 5: Extract Modal/Dialog Management

When: Component manages multiple modals with complex open/close states.

typescript
// ❌ Before: Multiple modal states in component
const AppInfo = () => {
  const [showEditModal, setShowEditModal] = useState(false)
  const [showDuplicateModal, setShowDuplicateModal] = useState(false)
  const [showConfirmDelete, setShowConfirmDelete] = useState(false)
  const [showSwitchModal, setShowSwitchModal] = useState(false)
  const [showImportDSLModal, setShowImportDSLModal] = useState(false)
  // 5+ more modal states...
}

// ✅ After: Extract to modal management hook
type ModalType = 'edit' | 'duplicate' | 'delete' | 'switch' | 'import' | null

const useAppInfoModals = () => {
  const [activeModal, setActiveModal] = useState<ModalType>(null)

  const openModal = useCallback((type: ModalType) => setActiveModal(type), [])
  const closeModal = useCallback(() => setActiveModal(null), [])

  return {
    activeModal,
    openModal,
    closeModal,
    isOpen: (type: ModalType) => activeModal === type,
  }
}

Common Mistakes to Avoid

❌ Over-Engineering
typescript
// ❌ Too many tiny hooks
const useButtonText = () => useState('Click')
const useButtonDisabled = () => useState(false)
const useButtonLoading = () => useState(false)

// ✅ Cohesive hook with related state
const useButtonState = () => {
  const [text, setText] = useState('Click')
  const [disabled, setDisabled] = useState(false)
  const [loading, setLoading] = useState(false)
  return { text, setText, disabled, setDisabled, loading, setLoading }
}
❌ Breaking Existing Patterns
  • Follow existing directory structures
  • Maintain naming conventions
  • Preserve export patterns for compatibility
❌ Premature Abstraction
  • Only extract when there's clear complexity benefit
  • Don't create abstractions for single-use code
  • Keep refactored code in the same domain area

References

  • frontend-testing - For testing refactored components

© PageAI-Pro, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 3 other files (references) in .agent/skills/component-refactoring of PageAI-Pro/ralph-loop.

  • SKILL.md
  • references/complexity-patterns.md
  • references/component-splitting.md
  • references/hook-extraction.md

Open the folder on GitHubat commit eba65eb

Compare with similar skills

Component Refactoring next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Component Refactoring compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Component Refactoring this skillPageAI-Pro/ralph-loop311—~1.8kAutomated safety check: PassMIT
Component Refactoringlangflow-ai/langflow156k—~3.5kAutomated safety check: PassMIT
Code Review And Qualityhylarucoder/hai-stack380—~934Automated safety check: PassMIT
React Composition Patternsvercel-labs/openreview1.7k58 repos~721Automated safety check: PassMIT
Vercel React Best Practicessanity-io/sanity6.4k130 repos~1.6kAutomated safety check: PassMIT
React Best Practicesmastra-ai/mastra29k—~1.9kAutomated safety check: PassCustom licence

Similar skills

  • Component Refactoring

    langflow-ai/langflow

    Refactor high-complexity React components in Langflow frontend.

    156k GitHub stars~3.5k tokensUpdated today
    DevelopmentAuto-check passed
  • Code Review And Quality

    hylarucoder/hai-stack

    Reviews a code change for correctness, security, maintainability, architecture, performance, and verification gaps, or performs a local code-smell review.

    380 GitHub stars~934 tokensUpdated 3 days ago
    DevelopmentAuto-check passed
  • React Composition Patterns

    vercel-labs/openreview

    Official

    Rules for structuring React components with composition instead of boolean props, covering compound components, lifted state, variants and React 19 changes.

    1.7k GitHub starsUsed in 58 repos~721 tokens
    Frontend & DesignAuto-check passed
  • Official

    React and Next.js performance optimization guidelines from Vercel Engineering.

    6.4k GitHub starsUsed in 130 repos~1.6k tokens
    Frontend & DesignAuto-check passed
  • React Best Practices

    mastra-ai/mastra

    React performance optimization guidelines from Mastra Engineering.

    29k GitHub stars~1.9k tokensUpdated today
    Frontend & DesignAuto-check passed
  • No Use Effect

    mattiacerutti/supernova

    Enforce the no-useEffect rule when writing or reviewing React code.

    187 GitHub starsUsed in 2 repos~1.7k tokens
    DevelopmentAuto-check passed

More from PageAI-Pro/ralph-loop

  • Vitest Best Practices

    PageAI-Pro/ralph-loop

    Comprehensive vitest testing patterns covering test structure, AAA pattern, parameterized tests, assertions, mocking, test doubles, error handling, async testing, and performance optimization.

    311 GitHub stars~1.2k tokensUpdated 1 mo ago
    Auto-check passed
  • E2E Tester

    PageAI-Pro/ralph-loop

    Playwright E2E testing patterns. An agent skill from PageAI-Pro/ralph-loop.

    311 GitHub stars~4.3k tokensUpdated 1 mo ago
    Auto-check: notes
  • Prd Creator

    PageAI-Pro/ralph-loop

    Guides creation of comprehensive Product Requirement Documents (PRDs) for software projects through structured questioning and validation, then generates implementation task lists in JSON format.

    311 GitHub stars~1.6k tokensUpdated 1 mo ago
    Auto-check: notes

Questions about Component Refactoring

What does Component Refactoring do?

Refactor high-complexity React components in frontend. An agent skill from PageAI-Pro/ralph-loop. Component Refactoring is an agent skill from PageAI-Pro/ralph-loop. Refactor high-complexity React components in frontend.

When should I use Component Refactoring?

Component Refactoring fits situations like: the user asks for code splitting; hook extraction; complexity reduction; you come across a component that is too complex to understand and refactor it.

How do I install Component Refactoring in Claude Code?

Run `npx skills add PageAI-Pro/ralph-loop --skill component-refactoring -a claude-code`. Or copy the skill folder (.agent/skills/component-refactoring in PageAI-Pro/ralph-loop) into .claude/skills/component-refactoring in your project. Claude Code loads it when a task matches its description.

How do I install Component Refactoring in Codex?

Run `npx skills add PageAI-Pro/ralph-loop --skill component-refactoring -a codex`. Or copy the skill folder (.agent/skills/component-refactoring in PageAI-Pro/ralph-loop) into .agents/skills/component-refactoring in your project. Codex loads it when a task matches its description.

Can I use Component Refactoring in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add PageAI-Pro/ralph-loop --skill component-refactoring -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/component-refactoring, .gemini/skills/component-refactoring, .github/skills/component-refactoring and .opencode/skills/component-refactoring in your project.

What does Component Refactoring need to run?

SKILL.md names no scripts, command-line tools or credentials: Component Refactoring is instructions for the agent only.

Does Component Refactoring access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Component Refactoring safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Component Refactoring use?

Component Refactoring is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Component Refactoring use?

About 1.8k tokens (SKILL.md is roughly 7.1k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 7.6k tokens, read only when the agent opens those files.

What are the alternatives to Component Refactoring?

Skills that share tags, products or a category with Component Refactoring: Component Refactoring (langflow-ai/langflow, 156k stars), Code Review And Quality (hylarucoder/hai-stack, 380 stars), React Composition Patterns (vercel-labs/openreview, 1.7k stars) and Vercel React Best Practices (sanity-io/sanity, 6.4k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Component Refactoring?

PageAI-Pro (a GitHub organization) maintains it in PageAI-Pro/ralph-loop, which has 311 GitHub stars. The repository holds 4 skills in this directory. The repository was last updated on August 31, 2026.

Source: PageAI-Pro/ralph-loop on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.