Skip to content

fix: Persist dark mode setting across page reloads#576

Open
shaonidutta wants to merge 1 commit intoJiyaGupta-cs:masterfrom
shaonidutta:fix/dark-mode-persistence
Open

fix: Persist dark mode setting across page reloads#576
shaonidutta wants to merge 1 commit intoJiyaGupta-cs:masterfrom
shaonidutta:fix/dark-mode-persistence

Conversation

@shaonidutta
Copy link

🐛 Bug Fix:

  • Dark mode setting now persists in localStorage
  • Theme preference is maintained across browser sessions
  • Initialize theme from localStorage on app load

🔧 Technical Changes:

  • Added useEffect hook for localStorage persistence
  • Enhanced theme state initialization with localStorage check
  • Automatic saving when theme state changes

✅ Resolves:

  • Dark mode resetting to light mode after page refresh
  • Improved user experience with persistent theme preference

Fixes #issue-dark-mode-persistence

Title and Issue number

Title: Dark and light mode bug fixed

Issue No.: #573

Close #573

Changes Made

  • Added localStorage persistence for dark/light mode theme setting
  • Enhanced theme state initialization to read from localStorage on app load
  • Implemented useEffect hook for automatic saving when theme changes
  • Fixed bug where theme preference was lost after page refresh/reload

Technical Details:

  • Modified src/Context/ShopContext.jsx to include localStorage functionality
  • Added useEffect import for React hooks
  • Enhanced theme state initialization with localStorage check
  • Automatic persistence of theme changes to browser storage

Screenshots (if applicable)

[Include any relevant screenshots or images to support your changes.]

Checklist

I have tested these changes locally.
I have reviewed the code and ensured it follows the project's coding standards.
I have updated the documentation (if necessary).
I have read the contributing guidelines.

 Bug Fix:
- Dark mode setting now persists in localStorage
- Theme preference is maintained across browser sessions
- Initialize theme from localStorage on app load

 Technical Changes:
- Added useEffect hook for localStorage persistence
- Enhanced theme state initialization with localStorage check
- Automatic saving when theme state changes

 Resolves:
- Dark mode resetting to light mode after page refresh
- Improved user experience with persistent theme preference

Fixes JiyaGupta-cs#573
@vercel
Copy link

vercel bot commented Jul 1, 2025

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 Jul 1, 2025 8:24am

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.

1 participant