How to create slices with immer and combine middlewares? #3056
Unanswered
robertluedke
asked this question in
Q&A
Replies: 1 comment 2 replies
-
I don't think that middleware is allowed in slices. I made zustand-namespaces to allow this sort of stuff. Or if you didnt want to use that, you would have to use the combine in the root of the store, not the slice. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello zustand community!
I've already found a suitable way to organize my zustand store especially with immer and combine to infer the types of my initial state and the store actions. My goal is not to have to explicitly create the types for the store actions or some computed get() selectors. So combine was the solution to realize it.
But now I wanna separate this store in some slices and I can't figure out how, because of TypeScript errors which occur through the usage of immer in common and combine in the slice files.
Could please somebody help me with these typescript issues?
Here is a TS Playground of this issue.
The current store without slices:
useExampleStore.ts
My slices approach with an example slice looks like this:
useBoundStore.ts
exampleSlice.ts
The ts errors:
In the useBoundStore.ts file I get the following ts error at
...createExampleSlice(...args)
:In the exampleSlice.ts file I get the following ts error in both
(state) => {
parts:Beta Was this translation helpful? Give feedback.
All reactions