Skip to content
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

Fix: Dark mode toggles off on page refresh #499

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

maheshsemwal
Copy link

Title and Issue number

Title : Dark mode gets turned off on refreshing page | Fixed
Description: This PR fixes the issue where the dark mode setting gets turned off when the page is refreshed. The theme preference is now properly saved and loaded from localStorage.
Issue No. : #472

Close #472

Changes Made

The changes i made to this part of the code ensure that the theme is correctly initialized from localStorage and that any changes to the theme are persisted back to localStorage. This allows the application to remember the user's theme preference even after the page is refreshed.

Original Code:

const [theme, setTheme] = useState("dark");

Updated Code:

const [theme, setTheme] = useState(() => {
    return localStorage.getItem('theme') || 'light';
});

useEffect(() => {
    localStorage.setItem('theme', theme);
}, [theme]);

Screenshots

before

ShopNex.and.8.more.pages.-.Personal.-.Microsoft.Edge.2024-06-08.20-22-52.mp4

After

ShopNex.and.8.more.pages.-.Personal.-.Microsoft.Edge.2024-06-08.20-23-23.mp4

Checklist

  • I have tested these changes locally.
  • I have reviewed the code and ensured it follows the project's coding standards.
  • I have read the contributing guidelines.

I'm contributing this under GirlScript summer of code.
Please review my PR and let me know if any changes are required.

Copy link

vercel bot commented Jun 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
shop-nex ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 8, 2024 3:25pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG 🐞: Dark mode gets turned off on refeshing page
1 participant