Usage
Return Value
| Property | Type | Description |
|---|---|---|
mode | "light" | "dark" | Current system color scheme preference |
Features
- Automatically updates when system preference changes
- Works with both modern and legacy browsers
- Handles SSR environments gracefully
Examples
Conditional Styling
With Theme Provider
Image Variants
Browser Support
The hook uses theprefers-color-scheme media query:
addEventListener) and legacy browsers (using the deprecated addListener method).
SSR Considerations
When running on the server (wherewindow is undefined), the hook defaults to "light" mode. The actual system preference will be detected on the client after hydration.