fn

useDark

v0.0.14testeddemo

Reactive dark mode boolean with system detection and storage persistence, built on useColorMode. Writing false while the system already prefers light (or true while it prefers dark) falls back to 'auto', so the mode keeps tracking the OS preference.

Examples

ts
const isDark = useDark();
isDark.value = true;
ts
// Toggle a data attribute instead of a class
const isDark = useDark({
  attribute: 'data-theme',
  valueDark: 'dark',
  valueLight: 'light',
});
ts
import { useToggle } from '@/composables/state/useToggle';

const isDark = useDark();
const toggleDark = useToggle(isDark);

Demo

Loading demo…

Signature

ts
export function useDark(options: UseDarkOptions ={ ... }

Parameters

ParameterTypeDescription
options?UseDarkOptionsOptions

Returns

UseDarkReturnA writable boolean ref; true when dark mode is active