When should we be using multiple stores instead of a single store with separate slices? #2496
-
Does it depend on size of the store? Is there a rule of thumb that should be followed? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
We follow just the AHA programming and is basically when you feel that something is getting difficult to maintain, that's the moment to start splitting your store or using slices. How can I know if I need to use multiple stores or multiple slices? well that's simple, if each part is independent from each other then multiple stores is the right path if not then multiple slices is the right path |
Beta Was this translation helpful? Give feedback.
-
My suggestion (as of now):
|
Beta Was this translation helpful? Give feedback.
-
@dai-shi @dbritto-dev You both advocate for a single store in some situations and multiple stores in others in this discussion thread. However, on the docs page it says a single zustand store is best practice: "Although Zustand is an unopinionated library, we do recommend a few patterns. [...] Your applications global state should be located in a single Zustand store." @dai-shi you say "If two things are totally isolated, multiple stores would be good". Okay, but would it be better than a single store with two slices, where each isolated part is stored in its own slice? If not, well then you are actually advocating for a single store. It's confusing that the maintainer of zustand recommends something that conflicts with the docs. Is the docs just outdated or what? |
Beta Was this translation helpful? Give feedback.
-
Can someone explain what pattern should I use for an ecommerce app. for exmaple, I have Screens
Should I use slice pattern and create 1 global store where user data, cart data and product detail data reside or should I create three different store like |
Beta Was this translation helpful? Give feedback.
My suggestion (as of now):