vercel-composition-patterns
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.
Install
npx skills add https://github.com/vercel-labs/agent-skills --skill vercel-composition-patterns- title
- Define Generic Context Interfaces for Dependency Injection
- impact
- HIGH
- impactDescription
- enables dependency-injectable state across use-cases
- tags
- composition, context, state, typescript, dependency-injection
Define Generic Context Interfaces for Dependency Injection
Define a generic interface for your component context with three parts:
state, actions, and meta. This interface is a contract that any provider
can implement—enabling the same UI components to work with completely different
state implementations.
Core principle: Lift state, compose internals, make state dependency-injectable.
Incorrect (UI coupled to specific state implementation):
Correct (generic interface enables dependency injection):
UI components consume the interface, not the implementation:
Different providers implement the same interface:
The same composed UI works with both:
Custom UI outside the component can access state and actions:
The provider boundary is what matters—not the visual nesting. Components that
need shared state don't have to be inside the Composer.Frame. They just need
to be within the provider.
The ForwardButton and MessagePreview are not visually inside the composer
box, but they can still access its state and actions. This is the power of
lifting state into providers.
The UI is reusable bits you compose together. The state is dependency-injected by the provider. Swap the provider, keep the UI.