sourcebot/packages/web/src/hooks/useThemeNormalized.ts

22 lines
545 B
TypeScript
Raw Normal View History

'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;
2024-09-11 05:23:40 +00:00
}, [_theme, systemTheme, defaultTheme]);
return {
theme,
systemTheme,
setTheme,
};
}