diff --git a/lib/providers/theme/themeContext.tsx b/lib/providers/theme/themeContext.tsx index d8795c22..c74520fc 100644 --- a/lib/providers/theme/themeContext.tsx +++ b/lib/providers/theme/themeContext.tsx @@ -1,13 +1,13 @@ -import { createContext } from "react"; +import React from "react"; export type Theme = "dark" | "light"; export type ThemeContextValue = { theme: Theme; - toggleTheme: (theme: Theme) => void; + toggleTheme: () => void; }; -export const ThemeContext = createContext({ +export const ThemeContext = React.createContext({ theme: "light", toggleTheme: () => {}, }); diff --git a/lib/providers/theme/themeProvider.tsx b/lib/providers/theme/themeProvider.tsx index 2f5b71c5..f214d6ba 100644 --- a/lib/providers/theme/themeProvider.tsx +++ b/lib/providers/theme/themeProvider.tsx @@ -15,8 +15,9 @@ export const ThemeProvider = ({ children, theme }: ThemeProviderProps) => { const systemPrefersDark = useMediaQuery("(prefers-color-scheme: dark)"); - const toggleTheme = (updatedTheme: Theme) => { - setSelectedTheme(updatedTheme); + const toggleTheme = () => { + const newTheme = currentTheme === "dark" ? "light" : "dark"; + setSelectedTheme(newTheme); }; useEffect(() => { @@ -25,18 +26,9 @@ export const ThemeProvider = ({ children, theme }: ThemeProviderProps) => { setCurrentTheme(theme); }, [selectedTheme, systemPrefersDark]); - useEffect(() => { - const root = document.documentElement; - if (currentTheme === "dark") { - root.classList.add("theme--dark"); - } else { - root.classList.remove("theme--dark"); - } - }, [currentTheme]); - return ( -
{children}
+
{children}
); };