preact-missing-hooks
Version:
A lightweight, extendable collection of missing React-like hooks for Preact — plus fresh, powerful new ones designed specifically for modern Preact apps.
22 lines (21 loc) • 626 B
TypeScript
export type PreferredTheme = "light" | "dark" | "no-preference";
/**
* A Preact hook that returns the user's preferred color scheme based on the
* `prefers-color-scheme` media query. Updates reactively when the user changes
* their system or browser theme preference.
*
* @returns The preferred theme: 'light', 'dark', or 'no-preference'
*
* @example
* ```tsx
* function ThemeAwareComponent() {
* const theme = usePreferredTheme();
* return (
* <div data-theme={theme}>
* Current preference: {theme}
* </div>
* );
* }
* ```
*/
export declare function usePreferredTheme(): PreferredTheme;