useColorScheme
The system color-scheme preference as the cross-platform ColorScheme contract. Browser composable — import from @sigx/use-web.
import { component, render } from 'sigx';
import { useColorScheme } from '@sigx/use-web';
const Scheme = component(() => {
const scheme = useColorScheme();
return () => <p>System prefers: {scheme.value}</p>;
});
render(<Scheme />, "#app");
The return is a ReadSignal<ColorScheme> where ColorScheme is 'light' | 'dark' — no-preference maps to 'light':
import { effect } from 'sigx';
const scheme = useColorScheme();
effect(() => (document.documentElement.dataset.theme = scheme.value));
ReadSignalpreserves the literal union:scheme.valueis typed'light' | 'dark', not widened tostring. That's the whole reason single-value returns are structural — see Outputs.
Signature
function useColorScheme(options?: UseColorSchemeOptions): ReadSignal<ColorScheme>;
ColorScheme is a cross-platform contract — the same return shape as Lynx's useSystemColorScheme, so theme code ports across platforms unchanged.
Options
| Option | Type | Default | Description |
|---|---|---|---|
ssrDefault | ColorScheme | 'light' | Value reported on the server / where matchMedia is unavailable. |
window | Window | defaultWindow | Override the window (SSR/testing). See Configurable*. |
SSR
On the server (no matchMedia) the signal reads ssrDefault — 'light' by default — then reads the real preference on mount.
See also
useMediaQuery— theprefers-color-schemequery underneath, untyped.useStorage— persist a user override of the system scheme.- Conventions → Cross-platform contracts — the
ColorSchemeshape shared with Lynx.
