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
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 0returnprev+1;});set((prev)=>{console.log(prev);// Expect 1returnprev+1;});set((prev)=>{console.log(prev);// Expect 2returnprev+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
The text was updated successfully, but these errors were encountered:
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:
All
set
calls will receive0
.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.2react
version: 18.2.0react-dom
version: 18.2.0typescript
version: 5.2.2The text was updated successfully, but these errors were encountered: