mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-30 09:03:15 +00:00
Fix: Prevent flash in dark mode
This commit is contained in:
@@ -82,6 +82,7 @@ export function useDarkTheme() {
|
||||
};
|
||||
|
||||
const [isDarkTheme, setIsDarkTheme] = useState<boolean>(getInitialTheme());
|
||||
const [componentMounted, setComponentMounted] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
||||
@@ -102,11 +103,12 @@ export function useDarkTheme() {
|
||||
} else {
|
||||
document.body?.classList.remove('dark');
|
||||
}
|
||||
setComponentMounted(true);
|
||||
}, [isDarkTheme]);
|
||||
|
||||
const toggleTheme = () => {
|
||||
setIsDarkTheme(!isDarkTheme);
|
||||
};
|
||||
|
||||
return [isDarkTheme, toggleTheme] as const;
|
||||
return [isDarkTheme, toggleTheme, componentMounted] as const;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user