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

Usage of Updating multiple stores

MilesLeeeeee opened this issue · comments

Summary

Hello,I tried to use the Slices pattern following the documentation

image
Updating multiple stores seems inconsistent with actual usage

i found a way from #2045

It seems that using get() is correct?

Link to reproduction

https://codesandbox.io/s/recursing-proskuriakova-qmyz2n?file=/store/zustand.ts

@MilesLeeeeee the usage of create slice functions inside of actions is wrong. You should always use get.

Note: since you want to use get state in your create slice function you should pass set and get not only set. For instance: instead of createFishSlice(set) should be createFishSlice(set, get) or createFishSlice(...a)

@dai-shi seems that zustand docs page is outdated, would you mind deploying the latest version?

@dbritto-dev yes,Using get() is right, thanks a lot !!!