React Composition
Refactor overloaded React components into explicit variants and composable parts.
npx skills add vercel-labs/agent-skills --skill vercel-composition-patterns What it does
A component with many boolean options can hide conflicting states and make changes difficult to reason about. This skill gives the agent patterns for restructuring the component API around composition, shared state, and explicit variants.
What changes after install
- Encourages compound components instead of adding more behavior flags.
- Separates state implementation from the interface consumed by components.
- Provides React-version-specific guidance alongside general composition patterns.
Install
Run this command with Node.js 22.20 or later and select your agent in the Skills CLI.
npx skills add vercel-labs/agent-skills --skill vercel-composition-patterns Before using React Composition
- Provide a React codebase and its installed React version. The React 19 API section applies only to React 19 or later; skip it for earlier versions.
Read the reviewed setup instructions for the selected workflow.
When to use it
- Refactoring a reusable component with many interacting boolean props.
- Designing a component library whose pieces need shared state.
When not to use it
- Rewriting a small, clear component solely to introduce a provider.
- Using React 19-only advice in an older React application.
A concrete refactoring target
Imagine a dialog component with flags for editing, confirming, loading, compact mode, and destructive actions. Some combinations are nonsensical, yet every caller can construct them. Ask the agent to list the meaningful variants, identify shared behavior, and propose a composition API before changing the implementation. The aim is to make valid usage clearer while preserving focus handling, keyboard behavior, and existing interactions.
The upstream material discusses compound components, lifting state into providers, and explicit variants. Its state-interface guidance separates what consumers need—state, actions, and related metadata—from how the provider stores or retrieves that information. This is especially useful when a component library must support more than one source of state.
Bound the change
Provide existing call sites, behavior tests, and the React version. A proposed API that looks elegant in one example may be awkward for the actual callers. Ask the agent to migrate a representative usage first and describe any breaking changes, rather than replacing every component in the repository.
The skill includes a section specifically for React 19 APIs. Check your installed version before adopting those recommendations; the source explicitly separates them from the general patterns.
Decide whether this is the right skill
This is a structural refactoring guide, not a performance benchmark or a collection of ready-made components. Use React Performance when you have a waterfall, bundle, or rendering issue. Use React Composition when the interface itself makes code hard to understand or extend. A simpler component may need no provider at all. SkillDex reviewed the upstream instructions and did not run a component migration with this skill.
Related workflows
FAQ
- Does the whole skill require React 19?
- No. Its composition guidance is broader, but the source marks the React 19 API section as version-specific.
- Is this a visual design system?
- No. It focuses on component architecture and API design rather than providing a finished visual theme.