Agent skill
react-code-smells
Principal-engineer-level React refactoring patterns for eliminating code smells. Covers prop drilling, state explosion, component composition, abstraction quality, coupling, hooks, rendering patterns, and testability. Use when refactoring existing React codebases, reviewing PRs for architectural issues, or identifying technical debt in React applications.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/react-code-smells
SKILL.md
Principal Engineering React Best Practices
Principal-engineer-level refactoring guide for React applications. Contains 42 rules across 8 categories, prioritized by impact from critical (state architecture, composition) to incremental (testability). Each rule includes code smell indicators, before/after examples, and safe transformation steps.
When to Apply
Reference these guidelines when:
- Refactoring existing React codebases
- Reviewing PRs for architectural issues
- Identifying technical debt
- Planning large-scale refactoring efforts
- Deciding whether to extract, inline, or restructure components
- Improving testability of React code
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | State Architecture | CRITICAL | state- |
| 2 | Component Composition | CRITICAL | comp- |
| 3 | Abstraction Quality | HIGH | abs- |
| 4 | Coupling & Cohesion | HIGH | couple- |
| 5 | Hook Hygiene | MEDIUM-HIGH | hook- |
| 6 | Render Patterns | MEDIUM | render- |
| 7 | Side Effect Management | MEDIUM | effect- |
| 8 | Testability | LOW-MEDIUM | test- |
Quick Reference
1. State Architecture (CRITICAL)
state-prop-drilling-compound- Replace prop drilling with compound componentsstate-prop-drilling-composition- Replace prop drilling with component compositionstate-derived-calculation- Replace synchronized state with derived calculationsstate-machine-complex- Replace boolean explosion with state machinesstate-colocation- Colocate state with components that use itstate-reducer-consolidation- Consolidate related useState calls into useReducerstate-context-selector- Use context selectors to prevent cascade re-rendersstate-url-sync- Move shareable state to URL parameters
2. Component Composition (CRITICAL)
comp-render-props-extraction- Extract shared logic with render props or hookscomp-slots-over-props- Use slots/children instead of configuration propscomp-god-component-split- Split god components by responsibilitycomp-controlled-uncontrolled- Choose controlled vs uncontrolled deliberatelycomp-headless-extraction- Extract headless components for reusable behaviorcomp-props-spreading- Avoid untyped props spreadingcomp-polymorphic-as- Use polymorphic 'as' prop for flexible elementscomp-children-validation- Validate compound component children
3. Abstraction Quality (HIGH)
abs-premature-abstraction- Resist premature abstraction (Rule of Three)abs-over-configuration- Prefer composition over configurationabs-extract-custom-hook- Extract custom hooks for reusable logicabs-inline-vs-extract- Know when to inline vs extract componentsabs-wrong-abstraction-fix- Fix wrong abstractions by inlining firstabs-utility-vs-domain- Separate utility hooks from domain hooks
4. Coupling & Cohesion (HIGH)
couple-colocation-files- Colocate related files by featurecouple-dependency-injection- Use dependency injection for external servicescouple-interface-segregation- Apply interface segregation to propscouple-circular-deps- Break circular dependencies with inversioncouple-stable-imports- Import from stable public APIs only
5. Hook Hygiene (MEDIUM-HIGH)
hook-dependency-stability- Ensure hook dependencies are stablehook-composition-over-size- Compose small hooks rather than one large hookhook-return-object-vs-tuple- Choose hook return type by use casehook-conditional-usage- Never call hooks conditionallyhook-naming-conventions- Follow hook naming conventions
6. Render Patterns (MEDIUM)
render-conditional-early-return- Use early returns for conditional renderingrender-list-key-stability- Use stable, unique keys for listsrender-avoid-inline-objects- Avoid inline objects in JSX propsrender-fragment-cleanup- Use fragments to avoid wrapper divs
7. Side Effect Management (MEDIUM)
effect-to-event-handler- Move event responses from effects to handlerseffect-cleanup-required- Always clean up effect side effectseffect-single-responsibility- Separate unrelated effectseffect-avoid-unnecessary- Remove effects that aren't synchronization
8. Testability (LOW-MEDIUM)
test-seam-creation- Create seams for testable componentstest-behavior-over-implementation- Test behavior, not implementation detailstest-extract-for-testability- Extract logic to hooks for testabilitytest-mock-boundaries- Mock at boundaries, not internal details
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
Related Skills
- For React 19 API best practices, see
reactskill - For React core principles, see
react-principle-engineerskill - For form handling, see
react-hook-formskill
References
- react.dev - Official React documentation
- kentcdodds.com - Advanced React patterns
- patterns.dev - Design patterns in JavaScript
- testing-library.com - Testing best practices
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?