Skip to main content
The 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

Use merge.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):
This also works when overriding arrays with primitives:

React Components

React components and elements are not merged, but replaced:

Internal Implementation

From packages/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