component-refactor

Refactor duplicated React learning components into reusable hooks and a BaseLearningSystem component.

Updated Aug 25, 2025
One-click install
npx skills add https://github.com/joaopelegrino/app-controle --skill component-refactor
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: component-refactor
Source: https://github.com/joaopelegrino/app-controle/tree/main/.claude/skills/component-refactor
Command: npx skills add https://github.com/joaopelegrino/app-controle --skill component-refactor

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill tackles the problem of extensive code duplication (currently ~25% or 800 lines) across similar React components, leading to high maintenance costs and inconsistent codebases. It streamlines development by promoting reusable, generic components and custom hooks.

Core Features & Use Cases

  • Duplicate Code Elimination: Identify and refactor repetitive logic into reusable custom hooks (e.g., useAutoSaveNotes, useModuleProgress).
  • Generic Component Creation: Develop a BaseLearningSystem component to serve as a template for multiple learning systems, drastically reducing boilerplate.
  • Modular Subcomponents: Extract common UI blocks (e.g., Breadcrumb, ProgressBar, NotesSection) into shared, reusable components.
  • Use Case: Transform five highly duplicated *LearningSystem.jsx components into a single BaseLearningSystem component, reducing 800 lines of repeated code to a minimal, maintainable structure.

Quick Start

Use the component-refactor skill to extract the auto-save logic from CLearningSystem.jsx into a new useAutoSaveNotes.js custom hook.

Frequently Asked Questions about component-refactor

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

FAQPage Schema
How do I refactor duplicate React components into reusable ones?

Refactoring duplicate React components involves extracting common logic into custom hooks and creating a generic base component. Identify repeated state management, side effects, and UI patterns across similar components, then consolidate them into a single parameterized component with props-based configuration for video, modules, progress, and callbacks.

How can I eliminate code duplication in React learning systems?

Extract shared logic into custom hooks like useAutoSaveNotes and useModuleProgress, then use a single BaseLearningSystem component configured via props instead of maintaining separate *LearningSystem components. This approach reduces ~800 lines of duplicated code by 80% while standardizing state management and localStorage persistence.

What's the best way to create reusable React components from similar learning modules?

Build a generic BaseLearningSystem component that accepts configuration props for layout, video, modules, and navigation. Extract common UI blocks like Breadcrumb, ProgressBar, and NotesSection into modular subcomponents, and pull repetitive logic into custom hooks to serve multiple learning system variants.

Can I use custom hooks to share state logic across React components?

Yes. Custom hooks like useAutoSaveNotes and useModuleProgress encapsulate shared state management and side effects, allowing multiple components to reuse the same logic without duplication. This pattern enables consistent behavior across learning systems while maintaining clean, maintainable code.

Do I need to rewrite all my React components to reduce duplication?

No. You can incrementally refactor by extracting one custom hook at a time from your most duplicated components, then consolidate similar components into a single parameterized base component. Start with high-impact patterns like auto-save logic or progress tracking.

What are the limitations of using a generic base component for multiple learning systems?

A generic base component works best when learning systems share core patterns like video playback, module navigation, and progress tracking. If systems require deeply different layouts or specialized interactions, excessive conditional rendering in props can reduce maintainability; in those cases, extract only the truly shared logic into hooks.