mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-05 09:20:07 +08:00
36 lines
782 B
TypeScript
36 lines
782 B
TypeScript
/**
|
|
* useTheme hook for managing theme throughout the application
|
|
*/
|
|
import { useEffect, useState } from "react";
|
|
import {
|
|
setTheme,
|
|
getStoredTheme,
|
|
initializeTheme,
|
|
type Theme,
|
|
} from "@/lib/theme";
|
|
|
|
export function useTheme() {
|
|
const [theme, setThemeState] = useState<Theme | null>(null);
|
|
const [isLoaded, setIsLoaded] = useState(false);
|
|
|
|
useEffect(() => {
|
|
// Initialize theme from localStorage
|
|
const initialTheme = initializeTheme();
|
|
setThemeState(initialTheme);
|
|
setIsLoaded(true);
|
|
}, []);
|
|
|
|
const updateTheme = (newTheme: Theme) => {
|
|
setTheme(newTheme);
|
|
setThemeState(newTheme);
|
|
};
|
|
|
|
return {
|
|
theme: theme || "light",
|
|
isLoaded,
|
|
setTheme: updateTheme,
|
|
isDark: theme === "dark",
|
|
isLight: theme === "light",
|
|
};
|
|
}
|