Basic Composition
Userecast.compose() to combine multiple style objects:
Why Use Composition?
Reusability
Share style modules across different components for consistency
Maintainability
Update one style module and all composed components inherit the changes
Separation of Concerns
Keep different styling concerns (colors, sizes, states) in separate modules
Testing
Test individual style modules in isolation before composing them
How Composition Works
Later style objects override earlier ones for conflicting properties:Base Classes - Concatenated
Base Classes - Concatenated
Base classes from all style objects are combined:
Variants - Deep Merged
Variants - Deep Merged
Variant groups are merged, with later objects adding to or overriding:
Modifiers - Deep Merged
Modifiers - Deep Merged
Modifiers from all style objects are combined:
Composition Patterns
Layer-Based Composition
Organize styles in logical layers from general to specific:Layer Pattern
Feature-Based Composition
Build components by composing specific features:Shared Style Libraries
Create reusable style modules that work across components:Shared Modules
TypeScript Support
Composed style objects maintain full TypeScript support:Performance Tips
Compose Once
Compose Once
Create composed styles outside components, not on every render:
Keep Composition Reasonable
Keep Composition Reasonable
Limit composition to 3-5 style objects for optimal performance:
Best Practices
Order by Specificity
Compose from most general to most specific to ensure proper overrides
Single Responsibility
Each style module should have one clear purpose (colors, layout, states, etc.)
Consistent Naming
Use consistent variant and modifier names across all style modules
Test Modules
Test individual style modules before composing them together