Stop Rebuilding UI

Shadcn.io is not affiliated with official shadcn/ui

React useTernaryDarkMode Hook

React useTernaryDarkMode hook for light/dark/system theme modes. Persists preference, respects OS setting. TypeScript ready.

Implement proper dark mode with system preference support. useTernaryDarkMode manages three states: light, dark, and system—the gold standard for theme switching. System mode follows OS prefers-color-scheme and updates live when user changes system settings. Manual light/dark overrides system preference. Persists to localStorage. Returns isDarkMode boolean for conditional styling, current mode string, setter for direct control, and toggle for cycling through modes. All preferences sync across tabs. Perfect for theme switchers, settings pages, or anywhere users should choose between explicit themes or following system preference. Works with Next.js, Tailwind dark mode.

React useTernaryDarkMode Hook preview

Scroll to load preview

Installation

FAQ

Was this page helpful?

Sign in to leave feedback.