vercel-composition-patterns

Refactor React component APIs into compound components with context providers.

12|Updated Dec 25, 2024
One-click install
npx skills add https://github.com/whyte25/reusables --skill vercel-composition-patterns-whyte25
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vercel-composition-patterns
Source: https://github.com/whyte25/reusables/tree/main/.agents/skills/vercel-composition-patterns
Command: npx skills add https://github.com/whyte25/reusables --skill vercel-composition-patterns-whyte25

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It helps you eliminate boolean prop proliferation and improve maintainability by restructuring React components into composable compound components with lifted state.

Core Features & Use Cases

  • Avoid boolean prop proliferation: replace tangled conditional rendering with composition-based variants.
  • Use compound components with context: design a Provider + subcomponents so internal pieces share state via a consistent contract.
  • Lift state into provider components: enable sibling/overlay UI (previews, buttons, dialogs) to read and act on shared state without prop drilling.
  • Prefer children over render props: improve readability and compositional flexibility when building reusable APIs.
  • Apply React 19 API guidance: refactor away from forwardRef patterns and use use() instead of useContext().

Quick Start

Ask an AI to refactor your component by replacing boolean modes with explicit variants and introducing a compound Provider-based context contract (state, actions, 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?

You refactor React components by replacing tangled conditional rendering with explicit variant subcomponents and compound component architecture. This eliminates boolean prop proliferation by structuring your API around composable pieces instead of overloaded configuration objects.

How do I lift state into context providers for compound components?

Lift state into context providers by establishing a Provider component that manages a shared interface of state, actions, and meta. Sibling UI elements like previews and dialogs can then read and modify this state directly without prop drilling.

Should I use children instead of render props for React composition?

Using children instead of render props improves readability and compositional flexibility when building reusable React APIs. This refactor simplifies component interfaces by passing UI structures directly as children rather than through function invocations.

How do I apply React 19 context and ref semantics during a refactor?

Apply React 19 semantics by replacing forwardRef patterns with direct ref props and switching from useContext() to the use() hook for context reads. This aligns your compound component refactor with modern React 19 data consumption standards.

When should I use compound components over render props in React?

Use compound components with a shared context contract when sibling or overlay UI elements need to interact through shared state without prop drilling. This approach replaces render props to provide better readability and explicit variant control.