sourcebot/packages/web/src/hooks/useThemeNormalized.ts
2024-10-17 16:31:18 -04:00

22 lines
No EOL
545 B
TypeScript

'use client';
import { useTheme as useThemeBase } from "next-themes";
import { useMemo } from "react";
export const useThemeNormalized = (defaultTheme: "light" | "dark" = "light") => {
const { theme: _theme, systemTheme, setTheme } = useThemeBase();
const theme = useMemo(() => {
if (_theme === "system") {
return systemTheme ?? defaultTheme;
}
return _theme ?? defaultTheme;
}, [_theme, systemTheme, defaultTheme]);
return {
theme,
systemTheme,
setTheme,
};
}