usePreferredColorScheme
Browser & deviceTrack the user's preferred color scheme (prefers-color-scheme)
Install
$ npm install @usefy/use-preferred-color-schemeQuick start
usePreferredColorScheme.tsx
import { usePreferredColorScheme } from "@usefy/use-preferred-color-scheme";
const scheme = usePreferredColorScheme(); // "light" | "dark"API reference
usePreferredColorScheme(options?): "light" | "dark"
options.defaultScheme— scheme returned on the server / whenmatchMediais unavailable (default"light").options.initializeWithValue— whentrue(default), the real preference is read synchronously on the first client render. Set tofalseto renderdefaultSchemeon the first client render and defer the real read to a post-commit effect, avoiding a hydration mismatch when the server rendereddefaultScheme.
Go deeper
This page is the quick reference. For every example, prop, and edge case, read the full README — or open Storybook to change props live.