Skill library

Agent skill Frontend

React Composition Patterns

Build reusable component APIs with compound components, shared state and explicit variants instead of growing boolean props.

  • React
  • Components
  • Architecture

Install the skill

Installation method

Run the command from your project root with Node.js and npm.

npx skills@latest add vercel-labs/agent-skills --skill vercel-composition-patterns --agent claude-code --yes

Check this file in your project.claude/skills/vercel-composition-patterns/SKILL.md

Other ways to install
  • Choose an assistant interactively

    npx skills@latest add vercel-labs/agent-skills --skill vercel-composition-patterns

    Select your assistant and choose the project installation scope.

    Official instructions

The tested Skills CLI 1.10.0 requires Node.js 22.20 or later. Open your React project in an assistant that can load the Skill. Have the component, its callers, and existing tests or stories available. Check which React versions the project supports before using the React 19 examples.

View operation manual

What this skill helps with

  • Replace growing boolean prop combinations with explicit variants.
  • Design compound components with shared context.
  • Clarify component APIs and state ownership.

Good for

  • Reusable component libraries
  • Components with many configuration variants
Installed skill name
vercel-composition-patterns
Official rule files
The rules/ directory covers architecture, state management, implementation patterns, and React 19 APIs.
What to bring
A shared component, representative call sites, and the interactions they rely on.
Deliverable
A component API with clear variants and state ownership, plus check results for existing callers.
Skill name
vercel-composition-patterns

Check what callers rely on before changing the API

A request without a baseline

Use vercel-composition-patterns to remove the boolean props from our shared modal.

The same flag can select a whole flow or represent a current state. Changing both at once can break defaults, callbacks, or keyboard behavior that callers rely on.

A refactor you can verify

  1. Map the prop combinations each caller actually uses and record their behavior.
  2. Compose named variants where workflows differ and keep state such as open or disabled explicit.
  3. Migrate one caller at a time and re-run the checks for the original interactions.

React Composition Patterns operation manual

Refactor a shared modal whose flags select different workflows, or give a filter sidebar and toolbar a shared source of state. Use the project’s existing UI primitives and verify each change through real callers.

Use an edit-project dialog and a delete confirmation to find which parts can be shared and which belong to a named variant.

Find the right composition rule

Point the assistant to the named file in the installed Skill’s rules/ directory and give it a real call site to inspect.

Several flags select the modal workflowVariants
Command or reference
patterns-explicit-variants
Examples
Compare the edit and delete call sites. Sketch named components around their actual differences.
A caller needs to arrange the dialog’s partsArchitecture
Command or reference
architecture-compound-components
Examples
Find which title, body, and actions callers already compose and which parts need shared dialog state.
Sibling controls need the same filter valuesState
Command or reference
state-lift-state
Examples
Locate the nearest shared owner of the sidebar and toolbar. Trace a change from control to results.
A UI slot is passed through a render callbackComposition
Command or reference
patterns-children-over-render-props
Examples
Try children for a footer the caller can supply directly. Check if a callback receives internal data before replacing it.
An example uses ref as a prop or reads context with use()React 19
Command or reference
react19-no-forwardref
Examples
Check every supported React version before applying the example. Choose ref and context APIs that work across that range.

React Composition Patterns troubleshooting

How do I make sure the assistant loaded the right Skill?

Open the project where you installed it, mention vercel-composition-patterns, and ask the assistant to identify its installed SKILL.md and the rule file it used. If your client has not discovered the installation, try opening a new session in that project.

Which boolean props should I keep?

Keep props such as open, disabled, or isSubmitting when they express real state with a clear contract. When several flags combine to select different layouts or actions, map the combinations callers use and consider named variants. Preserve existing defaults and callbacks during migration.

Can I follow the guide in a React 18 project?

Yes. Compound components, children, explicit variants, and shared state work with React 18. Keep React 18-compatible APIs such as useContext and forwardRef where needed. The separate React 19 rule and examples using the newer context or ref syntax require React 19 or later.