vercel-composition-patterns

Refactor React components with boolean props into explicit variants and lifted context providers.

Updated Nov 1, 2024
One-click install
npx skills add https://github.com/artreimus/ylang-labs-blog --skill vercel-composition-patterns-artreimus
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vercel-composition-patterns
Source: https://github.com/artreimus/ylang-labs-blog/tree/main/.agents/skills/vercel-composition-patterns
Command: npx skills add https://github.com/artreimus/ylang-labs-blog --skill vercel-composition-patterns-artreimus

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It helps you replace brittle React APIs that rely on many boolean props with maintainable component composition, so your UI remains flexible as features grow.

Core Features & Use Cases

  • Avoid Boolean Prop Proliferation: redesign components so state/variants don’t explode into hard-to-reason conditional logic.
  • Build Compound Components: use shared context so subcomponents access state/actions without prop drilling.
  • Lift State into Providers: move state ownership into provider components so sibling or external UI can share and modify it reliably.
  • Prefer Children over Render Props: improve readability and composition ergonomics for reusable component APIs.
  • Create Explicit Component Variants: replace ambiguous “mode” props with named variants like ThreadComposer or EditComposer.
  • Align with React 19 APIs: apply React 19 guidance such as using use() for context access patterns and treating ref as a regular prop.

Quick Start

Ask an AI agent to refactor your component by identifying every boolean prop mode and replacing it with explicit variant components that share a lifted context provider for state, actions, and meta.

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?

Refactor React components by replacing boolean props with explicit variant components sharing a lifted context provider. This eliminates brittle conditional logic and maintains UI flexibility as features grow.

What is the compound component pattern in React and when should I use it?

The compound component pattern uses shared context so subcomponents access state and actions without prop drilling. Use it when building reusable UI libraries or compound component systems to keep APIs clean and composable.

How do I lift state into context providers for React component composition?

Lift state into context providers by moving state ownership into provider components with dependency-injected context interfaces for state, actions, and meta. This allows sibling or external UI to share and modify state reliably.

Does this React refactoring approach work with React 19 APIs?

Yes, this approach aligns with React 19 APIs by applying the use() pattern for context access and treating ref as a regular prop. It ensures refactored compound components follow current React guidance.

Should I use children or render props for reusable React component APIs?

Prefer children over render props to improve readability and composition ergonomics for reusable component APIs. Render props can create readability friction, while children offer cleaner composition.

Why do explicit component variants replace mode props in React?

Explicit component variants replace ambiguous mode props to avoid conditional render paths and boolean prop proliferation. Named variants like ThreadComposer or EditComposer provide clearer, more maintainable APIs.