-
-
Notifications
You must be signed in to change notification settings - Fork 429
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: update useDarkMode to not reset with OS value on every refresh #557
base: master
Are you sure you want to change the base?
Conversation
|
This PR fixes it for me — was always reverting to the OS default on every page load. |
@juliencrn can you take a look? |
please merge this pr |
neeeeed |
Keep running into this issue repeatedly |
Can someone review and merge this |
Unfortunately @juliencrn is the only one how can approve and merge this :/ |
setStoredValue(readValue()) | ||
const value = readValue() | ||
setValue(value) | ||
setStoredValue(value) | ||
// eslint-disable-next-line react-hooks/exhaustive-deps |
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.
setValue already sets stored value, isnt it?
maybe we can remove the eslint now and fill the deps as the logic changed?
Fixes #512
This PR does two things:
1. Update useLocalStorage save initial value
The way things are now, useLocalStorage does not correctly represents the value in the
localStorage
. It returns a default value even if thekey
doesn't exist there yet and does not create it, meaning it returns a value that is not necessarily the truth (should beundefined
. This causes a problem inuseDarkMode
(and probably other hooks).The PR updates the hook to actually save the key/value in
localStorage
when the hook is called, preserving the hook's initial funcionality.2. Update
useDarkMode
to not reset with OS value on every refreshRemoves the
useIsomorphicLayoutEffect
because it's unnecessary. The valueisDarkMode
will always be correctly set.