Signature
Returns
'dark' | 'light' | 'system'
Current theme setting. Can be “dark”, “light”, or “system” (auto-detect from OS preferences)
'dark' | 'light'
Actual theme after system resolution. When theme is “system”, this reflects the detected OS preference (“dark” or “light”)
(theme: Theme) => void
Function to update the theme. Accepts “dark”, “light”, or “system”. Automatically persists to localStorage.
Usage
Basic Theme Toggle
Theme Selector with System Option
Using Resolved Theme
Complete Theme Menu
How It Works
Theme Resolution
When theme is set to “system”, the hook useswindow.matchMedia("(prefers-color-scheme: dark)") to detect the OS preference:
DOM Updates
The hook automatically applies the resolved theme to the document root:localStorage Persistence
Theme preference is automatically saved to localStorage when changed:Prerequisites
This hook must be used within aThemeProvider component. The provider is typically included automatically when using AppShell’s SidebarLayout:
Best Practices
- Respect User Preference: Default to “system” theme to respect OS-level preferences
- Provide All Options: Offer light, dark, and system options for maximum flexibility
- Visual Feedback: Show the current theme setting clearly in your UI
- Accessibility: Ensure both themes have sufficient contrast and are accessible