react-composition-patterns

Guides refactoring of React components using compound components, providers, and composition patterns.

Updated Jun 14, 2026
One-click install
npx skills add https://github.com/ironkid90-s/lucky5-v7 --skill react-composition-patterns-ironkid90-s
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: react-composition-patterns
Source: https://github.com/ironkid90-s/lucky5-v7/tree/main/.ptah/skills/composition-patterns
Command: npx skills add https://github.com/ironkid90-s/lucky5-v7 --skill react-composition-patterns-ironkid90-s

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? React components often accumulate boolean props like isThread or isEditing, creating exponential state combinations and unmaintainable conditional logic. This Skill provides structured rules for replacing prop proliferation with composition, making component codebases easier for humans and AI agents to maintain. ## Core Features & Use Cases - Compound Component Architecture: Structure complex components with shared context so consumers compose exactly the pieces they need. - State Lifting and Dependency Injection: Define generic context interfaces (state, actions, meta) so the same UI works with local state, Zustand, or server-synced providers. - Explicit Variants and React 19 APIs: Create self-documenting variant components instead of boolean modes, and apply React 19 changes like ref-as-prop and use() instead of useContext(). - Use Case: When refactoring a message Composer component overloaded with isThread, isEditing, and isForwarding flags, apply these rules to split it into ThreadComposer, EditComposer, and ForwardMessageComposer variants sharing compound internals. ## Quick Start Ask the agent to refactor a React component that has too many boolean props using the composition patterns in this skill.

Frequently Asked Questions about react-composition-patterns

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

FAQPage Schema
How do I refactor React components with too many boolean props?

Replace boolean props with composition by creating explicit variant components such as ThreadComposer or EditComposer. Each variant composes shared compound component pieces like Composer.Frame, Composer.Input, and Composer.Footer, eliminating hidden conditionals and impossible states.

What are compound components in React?

Compound components are a set of subcomponents sharing state through a common context rather than props. Consumers compose pieces like Composer.Header and Composer.Submit explicitly, while a provider injects state, actions, and meta into the shared context.

How do I share React state with components outside the main UI?

Lift state into a provider component that wraps the entire subtree. Any component inside the provider boundary, even siblings outside the visual component frame, can access state and actions via context without prop drilling, refs, or useEffect syncing.

Should I use children or render props for React composition?

Prefer children for composing static structure because they are more readable and compose naturally. Use render props only when the parent must pass data back to the child, such as rendering list items with per-item data.

Does forwardRef still work in React 19?

In React 19, ref is a regular prop, so forwardRef wrappers are unnecessary; accept ref directly in the component props. Additionally, use() replaces useContext() and can be called conditionally. These rules apply only to React 19 or later.

When should I not use compound component patterns?

Avoid the pattern for simple components with few consumers, where a single component with minimal props is clearer. The added provider and context interface complexity pays off only when multiple variants or swappable state implementations exist.