-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Darkmode toggler #260
Darkmode toggler #260
Conversation
@Sristi2004-developer is attempting to deploy a commit to the team ecell Team on Vercel. A member of the Team first needs to authorize it. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Dark mode doesn't persist after reload. FIX that |
still the same issue. Take help from your friends in E-cell |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider moving DOM manipulation and localStorage updates inside useEffect to prevent side effects during rendering.
src/context/ThemeContext.jsx
Outdated
} else { | ||
if (currentMode == "false") { | ||
document.body.classList.remove("dark-theme"); | ||
localStorage.setItem("isDarkMode", "false"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant Local Storage Update : updating local Storage multiple times within the render phase, which is unnecessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use UseEffect to update the document.body class and localStorage whenever isDarkMode changes.
Created a ThemeContext.jsx file which provides a DarkMode state to track whether the Dark mode is enabled and a toggleTheme function to switch between light and dark modes and used this context into the navbar component using useContext hook.