Skip to content

Commit

Permalink
fix: dark theme (#1096)
Browse files Browse the repository at this point in the history
  • Loading branch information
brettdorrans authored May 27, 2022
1 parent 7657411 commit c83c698
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/components/theme-provider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,19 @@ export const ThemeProvider: React.FC<ThemeProviderProps> = ({
const initialTheme: Theme = useTheme();
const baseTheme: Theme | undefined = mergeThemes(initialTheme, theme);

const [isDarkMode, setIsDarkMode] = React.useState<boolean>();
const [themeContext, setThemeContext] = React.useState<Theme | undefined>(
baseTheme
);

React.useEffect(() => {
const isDarkModePersisted =
const prefersDarkTheme =
(window.matchMedia &&
window.matchMedia('(prefers-color-scheme: dark)').matches) ||
localStorage.getItem('isDarkMode') === 'true';
setIsDarkMode(isDarkModePersisted);
}, [setIsDarkMode]);

React.useEffect(() => {
setThemeContext(
isDarkMode ? mergeThemes(baseTheme, darkTheme) : baseTheme
prefersDarkTheme ? mergeThemes(baseTheme, darkTheme) : baseTheme
);
}, [isDarkMode, baseTheme]);
}, [baseTheme, darkTheme]);

return (
<>
Expand Down

0 comments on commit c83c698

Please sign in to comment.