Skip to content

Commit

Permalink
fix: updated theme toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
meenakshi-deriv committed Mar 12, 2024
1 parent ae45ad8 commit 7748378
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
13 changes: 9 additions & 4 deletions lib/providers/theme/themeContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import React from "react";

export type Theme = "dark" | "light";

export const initialThemeState = {
theme: "light" as Theme,
toggleTheme: (() => null) as () => void,
export type ThemeContextValue = {
theme: Theme;
toggleTheme: () => void;
};

export const ThemeContext = React.createContext(initialThemeState);
export const ThemeContext = React.createContext<ThemeContextValue>({
theme: "light",
toggleTheme: () => {},
});

export default ThemeContext;
9 changes: 0 additions & 9 deletions lib/providers/theme/themeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ 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 (
<ThemeContext.Provider value={{ theme: currentTheme, toggleTheme }}>
<section className={`theme--${currentTheme}`}>{children}</section>
Expand Down

0 comments on commit 7748378

Please sign in to comment.