Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
Fix default theme
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitayutanov committed Sep 20, 2023
1 parent 19a4948 commit 5f8c122
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/contexts/Themes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ import { defaultThemeContext } from './defaults';
import type { Theme, ThemeContextInterface } from './types';

export const ThemesProvider = ({ children }: { children: React.ReactNode }) => {
let initialTheme: Theme = 'light';
// let initialTheme: Theme = 'light';

// get the current theme
const localThemeRaw = localStorage.getItem('theme') || '';
// const localThemeRaw = localStorage.getItem('theme') || '';

// Provide system theme if raw theme is not valid.
if (!['light', 'dark'].includes(localThemeRaw)) {
const systemTheme =
window.matchMedia &&
window.matchMedia('(prefers-color-scheme: light)').matches
? 'dark'
: 'light';

initialTheme = systemTheme;
localStorage.setItem('theme', systemTheme);
} else {
// `localThemeRaw` is a valid theme.
initialTheme = localThemeRaw as Theme;
}
// if (!['light', 'dark'].includes(localThemeRaw)) {
// const systemTheme =
// window.matchMedia &&
// window.matchMedia('(prefers-color-scheme: light)').matches
// ? 'dark'
// : 'light';

// initialTheme = systemTheme;
// localStorage.setItem('theme', systemTheme);
// } else {
// // `localThemeRaw` is a valid theme.
// initialTheme = localThemeRaw as Theme;
// }

// the theme mode
const [theme, setTheme] = React.useState<Theme>(initialTheme);
const [theme, setTheme] = React.useState<Theme>('light');
const themeRef = useRef(theme);

const toggleTheme = (maybeTheme: Theme | null = null): void => {
Expand Down

0 comments on commit 5f8c122

Please sign in to comment.