composition-patterns_skill

This skill guides refactoring with composition patterns to replace boolean props, enabling scalable, reusable React APIs and architecture.
  • JavaScript
  • Official

23k

GitHub Stars

4

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill vercel-labs/agent-skills --skill composition-patterns

  • AGENTS.md22.1 KB
  • metadata.json530 B
  • README.md2.1 KB
  • SKILL.md2.8 KB

Overview

This skill provides a curated set of React composition patterns that scale for component libraries and large apps. It helps you refactor components that suffer from boolean prop proliferation and design clearer, more maintainable APIs using compound components, providers, and modern React 19 considerations. The guidance focuses on practical refactors that make components easier for both humans and AI to reason about.

How this skill works

The skill inspects component design tasks and suggests rule-driven refactors such as replacing boolean props with explicit variant components, lifting state to providers, and structuring compound components around shared context. It flags architecture issues by priority (architecture, state, implementation patterns, React 19 APIs) and offers concrete patterns and code-level recommendations to implement each rule. Use it when reviewing or evolving component APIs to improve reuse and testability.

When to use it

  • Refactoring components with many boolean props that control behavior
  • Designing or maintaining a shared component library or design system
  • Implementing compound components that share state across children
  • Reviewing component architecture or onboarding contributors
  • Adopting React 19 APIs or modernizing context/state usage

Best practices

  • Avoid boolean props for mode switches; create explicit variant components instead
  • Lift shared state into a provider so sibling components can access and modify it
  • Encapsulate implementation details inside provider components; expose a small, typed interface
  • Prefer children composition and context over scattered render props or ad-hoc props
  • Follow clear rule priorities: fix architecture first, then state, then implementation details

Example use cases

  • Refactor a Toggle with dozens of boolean flags into a ToggleProvider and explicit Toggle.On/Toggle.Off children
  • Create a Modal library that exposes Modal, ModalHeader, ModalBody using shared context for open/close state
  • Replace a Button with boolean props like primary/secondary/ghost by exporting explicit PrimaryButton and GhostButton variants
  • Migrate code to React 19 by removing forwardRef-heavy patterns and adapting to updated hooks and context practices
  • Standardize state interfaces with {state, actions, meta} for easier dependency injection and testing

FAQ

Not always; boolean props are fine for trivial toggles. Prefer removing them when they multiply and create combinatorial complexity or when clearer explicit variants improve readability and API discoverability.

Does this require React 19?

No. Most patterns apply to any modern React version. React 19-specific recommendations are optional and only relevant when you upgrade to that runtime.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational
composition-patterns skill by vercel-labs/agent-skills | VeilStrat