You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The setValue setter function returned by useLocalStorage is re-evaluated every time,
resulting in a lot of re-writes when it is specified as a dependency of an effect or callback (while skipping including it as dependency sometimes results in missing storage write).
I suspect it should be wrapped in something like useCallback(..., [setStoredValue]) to return a more "stable" object avoiding that issue.
The text was updated successfully, but these errors were encountered:
alex-kowalczyk
changed the title
setter of useLocalStorage should be stable
setValue of useLocalStorage should not change at each rerender
Feb 25, 2022
The
setValue
setter function returned byuseLocalStorage
is re-evaluated every time,resulting in a lot of re-writes when it is specified as a dependency of an effect or callback (while skipping including it as dependency sometimes results in missing storage write).
I suspect it should be wrapped in something like
useCallback(..., [setStoredValue])
to return a more "stable" object avoiding that issue.The text was updated successfully, but these errors were encountered: