-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Persist in localStorage, but do not upgrade React state #46
Comments
My workaround at the moment:
|
I understand your scenario. Give me some time to think about this. I've seen people wanting to get the state only initially and then don't update it but I should think if there is a unifying solution that can fit all scenarios. |
Is this solution going to work for you:
As my users have written about the same problem I'm thinking of updating the readme. If this solution works for you I would think about explaining this scenario. The solution seems simple and elegant. |
Hey @rwieruch. Just a reminder. Did you have time to see what I'm proposing? |
I'm closing this because of a lack of activity. |
Hi @astoilkov thanks for this great library.
I ran into an edge case and was wondering if that's a feature you may wanna support in the future:
In my case, I want to call
setValue
for storing the value in local storage, but without updating React's state. In other words, when callingsetValue
, I do not want a state update and thus no re-render. Scenario: I only want to use useLocalStorageState to write to the local storage and to pick up the value from the storage for the initial rendering, in between I do not care about thevalue
anymore.This could probably be solved with another property in the
options
object, e.g.{ onlyWrite: true }
which would prevent the internalsetState
call. However, I can also understand if that's something the library is no supposed to offer, because it's after all a solution for syncing the local storage to React's state.The text was updated successfully, but these errors were encountered: