Question: How can store/middleware respond to lifecycle events? #792
Replies: 1 comment
-
It sounds like a right approach. Do you mean wrapping Can you create a small code snippet to illustrate the idea? It might give some hints to get a better approach. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, thanks for making Zustand! I have a quick question: what is the recommended way for Zustand stores (or middleware) to respond to store lifecycle events? Here is our situation:
It looks like under the hood,
create/useStoreis callingapi.subscribe/api.unsubscribe, which makes sense, but as far as I can tell there is no way for the store (or middleware) to react to the unsubscribe/destroy events, such that when the last subscriber is unsubscribed, the store can take some action. Any suggestions on how I should deal with this scenario? I can picture wrappingcreatein a function that adds some extra logic that will call lifecycle methods on the store, but I'm not sure if that's the right approach.Beta Was this translation helpful? Give feedback.
All reactions