Proposal for Enhanced Async Support in Zustand #2750
Unanswered
jiji-hoon96
asked this question in
Ideas
Replies: 1 comment 6 replies
-
Hi, thanks for opening up a new discussion. Let's see how others think. This is an open field for third-party libraries. So, feel free to create a package on your own. You can list it in I have a question. How do you support having two or more async slices in a store? Or, is it out of the scope? |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm writing to initiate a discussion about enhancing Zustand's capabilities for handling asynchronous actions, particularly for projects that don't require a full-fledged server state management library.
Zustand is highly regarded for its simplicity and flexibility in managing client-side state. However, I've noticed that it doesn't provide built-in support for handling complex asynchronous operations, which are common in many web applications. While libraries like React Query excel at managing server state, there's an opportunity for Zustand to offer a lightweight solution for projects that don't need such extensive features.
Proposal
I've developed a utility called createAsyncSlice, inspired by Redux Toolkit's createAsyncThunk. This utility provides a standardized way to handle loading, success, and error states for async actions within Zustand stores. Here are the key points
The implementation maintains Zustand's core principles of simplicity and flexibility.
I'd love to hear your thoughts on this proposal.
I look forward to your feedback and the possibility of contributing to Zustand's growth.
Code
Sample Code
💭 To add a few more words, AsyncSlice is available in the react marketplace with prefetch, Suspense, and more
Beta Was this translation helpful? Give feedback.
All reactions