Skip to content
React Composition Patterns

React Composition PatternsSkill

Added to Onei
v1.0.0
MIT
Repository Docs

Summary

Vercel's official skill for React component architecture — replace boolean prop proliferation with compound components, lifted state and explicit variants. Includes React 19 APIs.

Features

  • Rules ordered by impact across four categories
  • Compound components and context-sharing architecture
  • Replaces boolean prop proliferation with explicit variants
  • Provider-owned state and generic context interfaces
  • children over render props
  • React 19 guidance: no forwardRef, use() over useContext()
  • Per-rule reference files with correct and incorrect examples

Install This Skill

Add this skill to your favorite AI agent in a few steps.

Any AI agent

This skill is plain instructions — it works with any assistant that accepts custom instructions or system prompts.

  1. Copy the skill content with the button below.
  2. Paste it into your agent's instruction file or system prompt (for example AGENTS.md, .cursorrules, or a custom instructions field).
  3. Ask the agent to apply the skill whenever the task matches.

Skill Content

Markdown Content

Copy this content and use it with your preferred AI agent

---
name: vercel-composition-patterns
description:
  React composition patterns that scale. Use when refactoring components with
  boolean prop proliferation, building flexible component libraries, or
  designing reusable APIs. Triggers on tasks involving compound components,
  render props, context providers, or component architecture. Includes React 19
  API changes.
license: MIT
metadata:
  author: vercel
  version: '1.0.0'
---

# React Composition Patterns

Composition patterns for building flexible, maintainable React components. Avoid
boolean prop proliferation by using compound components, lifting state, and
composing internals. These patterns make codebases easier for both humans and AI
agents to work with as they scale.

## When to Apply

Reference these guidelines when:

- Refactoring components with many boolean props
- Building reusable component libraries
- Designing flexible component APIs
- Reviewing component architecture
- Working with compound components or context providers

## Rule Categories by Priority

| Priority | Category                | Impact | Prefix          |
| -------- | ----------------------- | ------ | --------------- |
| 1        | Component Architecture  | HIGH   | `architecture-` |
| 2        | State Management        | MEDIUM | `state-`        |
| 3        | Implementation Patterns | MEDIUM | `patterns-`     |
| 4        | React 19 APIs           | MEDIUM | `react19-`      |

## Quick Reference

### 1. Component Architecture (HIGH)

- `architecture-avoid-boolean-props` - Don't add boolean props to customize
  behavior; use composition
- `architecture-compound-components` - Structure complex components with shared
  context

### 2. State Management (MEDIUM)

- `state-decouple-implementation` - Provider is the only place that knows how
  state is managed
- `state-context-interface` - Define generic interface with state, actions, meta
  for dependency injection
- `state-lift-state` - Move state into provider components for sibling access

### 3. Implementation Patterns (MEDIUM)

- `patterns-explicit-variants` - Create explicit variant components instead of
  boolean modes
- `patterns-children-over-render-props` - Use children for composition instead
  of renderX props

### 4. React 19 APIs (MEDIUM)

> **⚠️ React 19+ only.** Skip this section if using React 18 or earlier.

- `react19-no-forwardref` - Don't use `forwardRef`; use `use()` instead of `useContext()`

## How to Use

Read individual rule files for detailed explanations and code examples:

```
rules/architecture-avoid-boolean-props.md
rules/state-context-interface.md
```

Each rule file contains:

- Brief explanation of why it matters
- Incorrect code example with explanation
- Correct code example with explanation
- Additional context and references

## Full Compiled Document

For the complete guide with all rules expanded: `AGENTS.md`

Description

React Composition Patterns is an official Vercel agent skill for the problem every component library eventually has: a component that started with two props and now takes eleven booleans, each one branching its render.

The skill organises its rules into four priority-ordered categories.

Component architecture (high impact). Do not add boolean props to customise behaviour — compose instead. Structure complex components as compound components sharing context, so consumers assemble the parts they need rather than toggling flags.

State management. Keep the provider as the only place that knows how state is managed, define a generic state/actions/meta context interface so implementations can be swapped by dependency injection, and lift state into provider components where siblings need to read it.

Implementation patterns. Prefer explicit variant components over boolean modes, and children over renderX render props.

React 19 APIs. A clearly gated section — skipped on React 18 and earlier — covering the removal of forwardRef and using use() in place of useContext().

Each rule carries a stable identifier such as architecture-avoid-boolean-props or state-context-interface, and expands to its own reference file with an explanation of why it matters, an incorrect example, a corrected example, and further context. A compiled AGENTS.md holds the whole guide for agents that prefer one document.

Who it is for. Engineers building design systems and shared component libraries, and anyone refactoring a component whose prop list has outgrown it. Vercel's stated rationale is that these patterns keep a codebase tractable for AI agents as well as for people — a component whose behaviour is visible in its composition is easier for a model to modify correctly than one hiding behaviour behind flags.

MIT-licensed, part of vercel-labs/agent-skills, installable with npx skills add vercel-labs/agent-skills.

Related Skills

New

Temporal's official skill for building durable workflows — SDK patterns across seven languages, plus the determinism rules that decide whether a workflow survives a replay.

4 views
New

Expo's official skill for building native-feeling screens: Apple HIG styling, semantic colors, SF Symbols, native controls, Reanimated, blur and liquid glass.

2 views
New

Pull unresolved CodeRabbit review threads from your PR and apply the fixes one at a time, treating every reviewer comment as untrusted input rather than an instruction.

5 views
New

Google's official skill for driving the gcloud CLI safely from an agent: validate every command against its own help text, cap the output, and refuse the operations that should never run unattended.

6 views 1 copies
Browse all skills →