Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply React composition patterns to build flexible, maintainable components without boolean prop sprawl
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
SKILL.md
1---2name: vercel-composition-patterns3description:4React composition patterns that scale. Use when refactoring components with5boolean prop proliferation, building flexible component libraries, or6designing reusable APIs. Triggers on tasks involving compound components,7render props, context providers, or component architecture. Includes React 198API changes.9license: MIT10metadata:11author: vercel12version: '1.0.0'13---1415# React Composition Patterns1617Composition patterns for building flexible, maintainable React components. Avoid18boolean prop proliferation by using compound components, lifting state, and19composing internals. These patterns make codebases easier for both humans and AI20agents to work with as they scale.2122## When to Apply2324Reference these guidelines when:2526- Refactoring components with many boolean props27- Building reusable component libraries28- Designing flexible component APIs29- Reviewing component architecture30- Working with compound components or context providers3132## Rule Categories by Priority3334| Priority | Category | Impact | Prefix |35| -------- | ----------------------- | ------ | --------------- |36| 1 | Component Architecture | HIGH | `architecture-` |37| 2 | State Management | MEDIUM | `state-` |38| 3 | Implementation Patterns | MEDIUM | `patterns-` |39| 4 | React 19 APIs | MEDIUM | `react19-` |4041## Quick Reference4243### 1. Component Architecture (HIGH)4445- `architecture-avoid-boolean-props` - Don't add boolean props to customize46behavior; use composition47- `architecture-compound-components` - Structure complex components with shared48context4950### 2. State Management (MEDIUM)5152- `state-decouple-implementation` - Provider is the only place that knows how53state is managed54- `state-context-interface` - Define generic interface with state, actions, meta55for dependency injection56- `state-lift-state` - Move state into provider components for sibling access5758### 3. Implementation Patterns (MEDIUM)5960- `patterns-explicit-variants` - Create explicit variant components instead of61boolean modes62- `patterns-children-over-render-props` - Use children for composition instead63of renderX props6465### 4. React 19 APIs (MEDIUM)6667> **⚠️ React 19+ only.** Skip this section if using React 18 or earlier.6869- `react19-no-forwardref` - Don't use `forwardRef`; use `use()` instead of `useContext()`7071## How to Use7273Read individual rule files for detailed explanations and code examples:7475```76rules/architecture-avoid-boolean-props.md77rules/state-context-interface.md78```7980Each rule file contains:8182- Brief explanation of why it matters83- Incorrect code example with explanation84- Correct code example with explanation85- Additional context and references8687## Full Compiled Document8889For the complete guide with all rules expanded: `AGENTS.md`90