Skip to content

How to create slices with immer and auto type inference for slice actions? #3056

Answered by robertluedke
robertluedke asked this question in Q&A
Discussion options

You must be logged in to vote

Heyho! Thank you very much for your input @mooalot

I just solved the problem without the combine middleware and published an own middleware for this solution: https://github.com/robertluedke/zustand-create-slices

With this middleware I get a well structured store with store slices. Each slice has its own namespace and I do not need to explicit create the types for the actions, just for the pure data state.

Bonus: I did add an automatic action name inference for the developer tools in the format "slice name/function name" like "bear/addBear". (which works with immer middleware and in the Firefox!! Both are issues right now in Zustand itself..)

Now I am totally happy to have this easy api t…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@robertluedke
Comment options

@mooalot
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by robertluedke
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants