useThemeSetting
stablefunction useThemeSetting(options?: UseThemeSettingOptions): UseThemeSettingResult
localStorage key used to persist the user override. Set to null to disable persistence (when the host app already owns theme state and only needs the system-preference subscription). Defaults to "motif:theme".
Theme to assume during SSR / before the first client effect runs. Browsers cannot know the user's system preference until JS runs, so the very first paint of a server-rendered page falls back to this. Defaults to "light".
Description
Reads the user's persisted override from localStorage (if any), falls back to
prefers-color-scheme, and subscribes to OS-level changes via matchMedia. Designed to pair
with <ThemeProvider> to produce an automatic light/dark experience without per-page wiring.
Web only. The hook reads window.matchMedia and window.localStorage; on native, supply your
own preference store and pass the result to <ThemeProvider active> directly.
UseThemeSettingResult
mode— the user's selected mode.'system'until they explicitly choose.resolved— the concrete theme to render. Equal tomodeunlessmode === 'system', in which case it is the OS preference.set(next)— updates the mode. Persists tolocalStoragewhenstorageKeyis set.
Types
SSR behaviour
The first server-rendered HTML uses defaultResolved (default 'light') since the OS
preference is unreachable from Node. Hydration runs the client effect and updates to the real
value; React's hydration model treats this as a normal post-mount state change — no warning.
To avoid the brief flash on dark-preferring users, write the resolved value to a cookie at SSR
time and pass it back in via defaultResolved.
Example
For a user-facing toggle:
Related
ThemeProvider— receivesresolvedon itsactiveprop.- Dark mode toggle — full UI recipe built on this hook.
useThemeName— reads the active theme; this hook writes it (indirectly, via the provider'sactive).