merge function and its merge.all variant are utilities for deeply merging Theme UI theme objects. They are used internally by ThemeProvider and can be used to combine themes manually.
Import
Signature
merge
Theme
required
The base theme object
Theme
required
The theme object to merge into the base
Theme
A new theme object with deeply merged properties from both themes
merge.all
Partial<Theme>[]
required
Any number of theme objects to merge together
Theme
A new theme object with deeply merged properties from all themes
Usage
Basic Merge
Merge two theme objects together:Merge Multiple Themes
Usemerge.all to combine three or more themes:
Extending a Theme
Merge Behavior
Deep Merging
The function deeply merges nested objects:Array Handling
Arrays in the second theme replace arrays in the first theme (not concatenated):React Components
React components and elements are not merged, but replaced:Internal Implementation
Frompackages/core/src/index.ts:96-122:
Examples from Tests
Deep Object Merge
Merge All
Use Cases
Theme Variants
Create theme variants by merging a base with modifications:Composing Preset Themes
Component Library Theming
Related
- ThemeProvider - Uses merge internally for nested themes
- Theme Specification - Structure of theme objects
- Presets - Pre-built themes to extend
