Skip to content

Use themes

Use createThemeContract to define stable token names:

const vars = createThemeContract({
color: {
text: null,
},
})

Use createTheme to provide concrete values:

const darkTheme = createTheme(vars, {
color: {
text: "#f5f5f5",
},
})

Wrap the relevant subtree with ThemeProvider:

<ThemeProvider theme={darkTheme}>{children}</ThemeProvider>

Use useThemedStyles, useThemedStyle, resolveThemeStyles, or resolveThemeTokens before render. Raw themed exports intentionally contain token references until runtime resolution.

For a focused read, use useThemeSelector and return a primitive or a memoized value:

const foreground = useThemeSelector((theme) => theme.color.text)

Selectors compare their result by reference, so avoid allocating a new object for an unchanged theme snapshot. The themed style hooks already retain stable resolved references for unchanged style and theme inputs.

  • using browser CSS variables like var(--brand) instead of a theme contract
  • reading themed style exports directly without resolving them
  • mixing “contract shape” and “concrete values” in the same module without clear naming