composition-patterns

Refactors React components using compound components, context providers, and composition patterns.

Updated Mar 28, 2026
One-click install
npx skills add https://github.com/po4yka/blog --skill composition-patterns-po4yka
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: composition-patterns
Source: https://github.com/po4yka/blog/tree/main/.claude/skills/composition-patterns
Command: npx skills add https://github.com/po4yka/blog --skill composition-patterns-po4yka

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 compound components, lifted state, and dependency-injected context. ## Core Features & Use Cases - Boolean Prop Elimination: Replace boolean prop combinations with explicit component variants and compound components backed by shared context. - State Lifting & Dependency Injection: Define generic context interfaces (state, actions, meta) so the same UI works with local state, Zustand, or server-synced providers. - React 19 API Guidance: Apply React 19 conventions such as ref-as-prop and use() instead of forwardRef and useContext(). - Use Case: When refactoring a message composer that has grown to accept isThread, isEditing, and isDMThread props, use this Skill to restructure it into explicit ThreadComposer, EditComposer, and ChannelComposer variants sharing compound internals. ## Quick Start Ask the AI to refactor a React component with many boolean props into compound components using the composition-patterns skill.

Frequently Asked Questions about 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 explicit variant components that compose shared internals. Create separate components like ThreadComposer or EditComposer, each composing the exact pieces it needs from a compound component, eliminating hidden conditionals and impossible states.

What are compound components in React?

Compound components are a pattern where a parent component shares state with its subcomponents through context rather than props. Consumers compose pieces like Composer.Input and Composer.Submit explicitly, accessing shared state via context without prop drilling.

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 needs to pass data back to the child, such as rendering list items with per-item data.

Does React 19 still require forwardRef?

No, React 19 makes ref a regular prop, so forwardRef is unnecessary. Function components can accept ref directly in their props, and use() replaces useContext() for reading context, with the added ability to be called conditionally.

How do I share state between sibling React components without prop drilling?

Lift state into a provider component that wraps the siblings. Components inside the provider access state and actions through context, so elements like a submit button or preview can live outside the main UI while still sharing its state.