pmndrs / zustand

🐻 Bear necessities for state management in React

Home Page:https://zustand-demo.pmnd.rs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

zustand concurrent update issue

zhaoyaoxin opened this issue · comments

zustand concurrent update issue

I'm having a problem when I'm modifying a state using zustand I call the update function twice in quick succession, but instead of initializing with the result of the first update the second update function uses the previous initial value causing the first update to be overwritten.
The original list is [1,2,3,4] The first update goes from [1,2,3,4] to [1,2,5,4] but the second update goes from [1,2,3,4] to [1,2,3,6] resulting in the final result of [1,2,3,6] The first update is overwritten.

image

"react": "^18.2.0"
"react-dom": "^18.2.0"
"zustand": "^4.3.8"
"immer": "^10.0.2"