vercel-composition-patterns

Refactor React components with boolean props into compound components using context.

Updated Aug 8, 2024
One-click install
npx skills add https://github.com/CAPJackie/x --skill vercel-composition-patterns-capjackie
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vercel-composition-patterns
Source: https://github.com/CAPJackie/x/tree/main/.agents/skills/vercel-composition-patterns
Command: npx skills add https://github.com/CAPJackie/x --skill vercel-composition-patterns-capjackie

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Eliminates fragile React component APIs caused by boolean prop proliferation by replacing configuration with explicit composition, lifted state, and compound component patterns.

Core Features & Use Cases

  • Avoid Boolean Prop Proliferation: Converts mode-heavy components (e.g., isThread/isEditing) into explicit, self-documenting variants.
  • Compound Components with Shared Context: Builds flexible subcomponent structures where internal parts consume shared state, actions, and meta via context.
  • Lift State into Providers: Enables sibling or external UI to access the same state and actions without prop drilling or awkward refs.
  • React 19 API Guidance: Uses React 19 conventions (ref as a regular prop and use() instead of useContext()) while refactoring.

Quick Start

Use this skill to refactor an existing React component that has multiple boolean props into explicit variants that share behavior through a context provider.

Frequently Asked Questions about vercel-composition-patterns

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

FAQPage Schema
How do I refactor React components to avoid boolean prop proliferation?

To avoid boolean prop proliferation in React components, refactor mode-heavy props into explicit, self-documenting variants using compound component patterns and shared context. This replaces fragile configuration props with scalable component composition.

What is the best way to share state across sibling React components without prop drilling?

The best way to share state across sibling React components without prop drilling is to lift the state into a context provider. This allows sibling or external UI elements to access the same state and actions directly via context.

How do compound components work with shared context in React 19?

Compound components with shared context in React 19 work by building flexible subcomponent structures where internal parts consume shared state, actions, and meta. React 19 conventions use the use() hook instead of useContext() for context access.

Do I need React 19 to use the use() hook for context access?

Yes, you need React 19 to use the use() hook for context access. This skill aligns with React 19+ conventions, using use() instead of useContext() and treating ref as a regular prop for composition-driven interfaces.

When should I use compound components instead of render props in React?

You should use compound components instead of render props in React when you want to eliminate render-prop patterns and enable scalable composition. This approach uses explicit variants and lifted state to create self-documenting component APIs.

Can I treat ref as a regular prop when refactoring React component architecture?

Yes, you can treat ref as a regular prop when refactoring React component architecture. React 19 supports regular prop-based ref handling, allowing you to build composition-driven interfaces without awkward ref forwarding.