react-code-smells
25
总安装量
25
周安装量
#7853
全站排名
安装命令
npx skills add https://github.com/pproenca/dot-skills --skill react-code-smells
Agent 安装分布
claude-code
20
codex
20
opencode
19
github-copilot
19
gemini-cli
17
cursor
15
Skill 文档
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