mcpField
C
composition-patterns

composition-patterns

github.com/blockmaticDevelopment1214 installsUpdated 5w ago
Repository

About composition-patterns

composition-patterns is a set of rules for React component architecture, guiding developers toward reusable APIs built with composition, compound components, and explicit variants. It also covers state placement and React 19 ref and use() guidance, while distinguishing server and client data.

Key features

  1. 01Prefer composition over boolean prop proliferation
  2. 02Use compound structures for complex components
  3. 03Lift client state only when siblings need it
  4. 04Compose with explicit variants and children
  5. 05Guidance for React 19 refs and use()

Use cases

  1. 01Refactor components with many boolean props
  2. 02Design reusable component library APIs
  3. 03Review component architecture and state management
  4. 04Build compound components or context providers

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/blockmatic/basilic-skills --skill composition-patterns

After installing, type/composition-patternsin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

metadata.json
README.md
references/
compiled.md
rules/
_sections.md
_template.md
architecture-avoid-boolean-props.md
architecture-compound-components.md
patterns-children-over-render-props.md
patterns-explicit-variants.md
react19-no-forwardref.md
state-context-interface.md
state-decouple-implementation.md
state-lift-state.md

Details

From the project README

React Composition Patterns

Composition patterns for building flexible, maintainable React components. Avoid boolean prop proliferation by using compound components, lifting state, and composing internals. Upstream: composition-patterns in vercel-labs/agent-skills.

Scope

  • Applies to: reusable component APIs, compound components, explicit variants, React 19 ref/use() changes
  • Does NOT cover: visual direction (frontend-design); Next.js caching or RSC data fetching (next-v16, vercel-react)

Assumptions

  • React 19+ in typical Basilic apps; skip the React 19 rule section on React 18
  • Server/client boundaries already exist; composition must not move server data into client-only providers

Principles

  • Prefer composition over boolean configuration for reused components
  • Lift client UI state only when siblings need it; keep server data on the server
  • Extract shared primitives after a second call site, not for one-off route UI

Constraints

MUST
  • Extract compound components only for a shared UI package or 2+ call sites, not a single route leaf
  • Keep React Server Components fetching their own data; pass server-rendered children into client leaves instead of lifting that data into a client provider
  • Leave URL-shareable state, async server state, and grouped local UI state on the libraries the project already uses (query-string parsers, TanStack Query, grouped-state hooks)—do not replace them with a generic context DI layer
SHOULD
  • Skip forwardRef unless a parent must attach a ref
  • Use explicit variant components instead of isX boolean modes on reused APIs
  • Prefer children over renderX props
AVOID
  • Premature abstractions around a one-off screen
  • Client providers whose only job is to re-export RSC-fetched props
  • Breaking existing 'use client' placement to “compose” everything

Interactions

When to apply

  • 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

PriorityCategoryImpactPrefix
1Component ArchitectureHIGHarchitecture-
2State ManagementMEDIUMstate-
3Implementation PatternsMEDIUMpatterns-
4React 19 APIsMEDIUMreact19-

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

Apply these only where the Constraints above allow. Do not lift server-owned data.

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 on React 18 or earlier.

  • react19-no-forwardref — Don't use forwardRef for new components. use() is optional for conditional context reads; useContext() remains supported.

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 why it matters, incorrect and correct examples, and extra context.

Full compiled guide (do not name this AGENTS.md; Cursor always-loads that filename): references/compiled.md

Comments

Markdown supported