react-composition-patterns

Refactors React components using compound components, lifted state, and context-based composition patterns.

3|1|Updated Mar 17, 2022
One-click install
npx skills add https://github.com/paulpessoa/menvo --skill react-composition-patterns-paulpessoa
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: react-composition-patterns
Source: https://github.com/paulpessoa/menvo/tree/main/.agent/skills/react-composition-patterns
Command: npx skills add https://github.com/paulpessoa/menvo --skill react-composition-patterns-paulpessoa

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 interfaces. ## Core Features & Use Cases - Boolean Prop Elimination: Replace boolean mode props with explicit variant components such as ThreadComposer or EditComposer that compose shared internals. - Compound Component Architecture: Structure complex components with shared context so subcomponents access state and actions without prop drilling. - Generic Context Interfaces: Define state, actions, and meta contracts so the same UI works with different providers, from local useState to global synced stores. - React 19 API Guidance: Covers ref-as-prop replacing forwardRef and use() replacing useContext for React 19 codebases. - Use Case: When refactoring a messaging composer that has grown to eight boolean props, apply these rules to split it into explicit variants backed by a shared provider, eliminating impossible states. ## Quick Start Ask the AI to refactor a React component with many boolean props into compound components using the rules 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 explicit variant components that compose shared internals. Instead of one Composer with isThread and isEditing flags, create ThreadComposer and EditComposer components that each compose the pieces they need from a shared compound component.

What are compound components in React?

Compound components are a pattern where a parent component and its subcomponents share state through context rather than props. Consumers compose pieces like Composer.Frame, Composer.Input, and Composer.Submit explicitly, avoiding hidden conditionals and prop drilling.

Should I use children or render props for React composition?

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

Does React 19 still require forwardRef?

No. In React 19, ref is a regular prop, so function components can accept ref directly without the forwardRef wrapper. React 19 also introduces use() as a replacement for useContext(), which can be called conditionally.

When should I lift state into a React provider component?

Lift state into a provider when sibling components outside the main UI need access to that state or its actions. This avoids useEffect syncing hacks and ref-based state reads, letting any component within the provider boundary consume the context.

When should I not use these React composition patterns?

Do not use this skill for React or Next.js performance optimization, which is out of its scope. The React 19 rules also do not apply to codebases running React 18 or earlier.