Conversation

Xedon

useLocalStorage can not handle batch updates correctly, this PR will fix that.

It does not call the update function with the current state in the local storage.
It uses the last "rendered" state which will not work if you call the callback multiple times without react rendering the component between calls.

Here is an example sandbox which shows our usecase.

In this Menu top left of the app.
image

If you Click show all or hide all this will do batch updates on the useLocalStorage which will only toggle the last column and not all columns due to this bug.
image

@thomaswright

This fix would also allow setState to be used in memoized functions and receive the up-to-date state for its update function.

Sign up for free to join this conversation on . Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.