Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix useLocalStorage batch updates not working #310

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

Open
Xedon wants to merge 1 commit into uidotdev:main
base: main
Choose a base branch
Loading
from Xedon:fix-useLocalStorage-batch-update

Conversation

Copy link

@Xedon Xedon commented Jun 10, 2024

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 reacted with thumbs up emoji
Copy link

thomaswright commented Sep 27, 2024
edited
Loading

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 GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /