Persist in localStorage, but do not upgrade React state
See original GitHub issueHi @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 calling setValue
, 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 the value
anymore.
This could probably be solved with another property in the options
object, e.g. { onlyWrite: true }
which would prevent the internal setState
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.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
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.
I’m closing this because of a lack of activity.