Skip to content
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

State updates in useLocalStorageValue are not queued like useState is. #1507

Open
rstepinski opened this issue Jan 30, 2024 · 0 comments
Open

Comments

@rstepinski
Copy link

Prior Issues

none

What is the current behavior?

Using multiple state updates from useLocalStorageValue, be it in different components or sequentially in the same component, are not queued. The last state update receives the initial state and not the state already altered by previous updates.

Steps to Reproduce

Consider the following code:

const { set } = useLocalStorageValue<number, number, true>('test', { defaultValue: 0 });

set((prev) => {
  console.log(prev); // Expect 0
  return prev + 1;
});
set((prev) => {
  console.log(prev); // Expect 1
  return prev + 1;
});
set((prev) => {
  console.log(prev); // Expect 2
  return prev + 1;
});

All set calls will receive 0.

What is the expected behavior?

State updates should be queued to allow for sequential state updates.
If this is not possible, it should be clearly mentioned in the documentation that the expected behavior differs from what we're used to with useState.

Environment Details

  • @react-hookz/web version: 24.0.2
  • react version: 18.2.0
  • react-dom version: 18.2.0
  • typescript version: 5.2.2
  • OS: Ubuntu
  • Browser: Chrome
  • Did this work in previous versions? didn't use previous versions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant