s
This commit is contained in:
@@ -34,16 +34,9 @@ function getInitialTheme(): Theme {
|
||||
}
|
||||
|
||||
export function ThemeProvider({ children }: { children: ReactNode }) {
|
||||
const [theme, setThemeState] = useState<Theme>("light");
|
||||
const [mounted, setMounted] = useState(false);
|
||||
const [theme, setThemeState] = useState<Theme>(() => getInitialTheme());
|
||||
|
||||
useEffect(() => {
|
||||
setThemeState(getInitialTheme());
|
||||
setMounted(true);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!mounted) return;
|
||||
const root = document.documentElement;
|
||||
if (theme === "dark") {
|
||||
root.classList.add("dark");
|
||||
@@ -55,7 +48,7 @@ export function ThemeProvider({ children }: { children: ReactNode }) {
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}, [theme, mounted]);
|
||||
}, [theme]);
|
||||
|
||||
const setTheme = useCallback((newTheme: Theme) => {
|
||||
setThemeState(newTheme);
|
||||
|
||||
Reference in New Issue
Block a user