Refactor React Components with Composition Patterns
React composition patterns to replace boolean-prop sprawl with compound components, lifted state, and explicit variants.
Why it matters
Improve the maintainability and flexibility of your React codebase by applying advanced composition patterns. This skill helps refactor components with excessive boolean props into more scalable and AI-friendly structures.
Outcomes
What it gets done
Apply compound components and context providers for better structure.
Refactor components to avoid boolean prop proliferation.
Implement state lifting for improved sibling component access.
Design more flexible and reusable component APIs.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/ag-composition-patterns | bash Overview
React Composition Patterns
Reference guide of React composition patterns for avoiding boolean-prop proliferation - compound components, lifted provider state with a generic context interface, explicit variant components instead of boolean modes, children over render props, and React 19-specific guidance (no forwardRef, use() over useContext()). Use it when refactoring components with many boolean props, building a reusable component library, designing a flexible component API, or reviewing component architecture. The React 19 section applies only to React 19+.
What it does
React Composition Patterns documents a set of rules for building flexible, maintainable React components by avoiding boolean-prop proliferation - the pattern where a component grows more and more isX/showY/variantZ boolean props to customize its behavior, eventually producing an unmanageable combinatorial explosion of states. Rules are grouped into four priority categories: component architecture (avoid boolean props, use compound components with shared context), state management (decouple implementation so only the provider knows how state works, define a generic context interface with state/actions/meta for dependency injection, lift state into provider components for sibling access), implementation patterns (explicit variant components instead of boolean modes, children over render props for composition), and React 19-specific APIs (no forwardRef, use use() instead of useContext() - applicable only on React 19+).
When to use - and when NOT to
Use it when refactoring a component that has accumulated many boolean props, building a reusable component library, designing a flexible component API, reviewing component architecture, or working with compound components or context providers. Skip the React 19 section entirely if the project is on React 18 or earlier - those rules don't apply.
Inputs and outputs
Each rule lives in its own file under rules/ (e.g. architecture-avoid-boolean-props.md, state-context-interface.md), containing a brief explanation of why it matters, an incorrect code example with explanation, a correct code example with explanation, and additional context/references. A full compiled document with every rule expanded is available at AGENTS.md for a single-pass read.
Integrations
The rules are designed to make a codebase easier for both humans and AI coding agents to work with as it scales - the compound-component and lifted-state patterns specifically reduce the surface area an agent has to reason about when extending a component.
Who it's for
React developers refactoring boolean-prop-heavy components, building component libraries, or reviewing architecture, who want a concrete rule set with incorrect/correct code pairs rather than vague "keep it composable" advice.
FAQ
Common questions
Discussion
Questions & comments ยท 0
Sign In Sign in to leave a comment.