Replies: 1 comment 9 replies
-
@ycmjason what you mean? the Ref: https://zustand.docs.pmnd.rs/apis/create#subscribing-to-state-updates |
Beta Was this translation helpful? Give feedback.
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
In my use cases of
store.subscribe
, I often need to clean up resources when the store state updates. However,subscribe()
does not currently support returning a cleanup function, making this process a bit cumbersome.Currently, I have to manually track and call cleanup functions like this:
To make this more ergonomic, I created a utility called
withCleanup
, which mimicsuseEffect
's cleanup behavior:This works well, but I think it would be even better if Zustand's
subscribe()
natively supported cleanup functions, allowing this:Proposal
Would it make sense to either:
withCleanup
utility in Zustand?subscribe()
to allow returning a cleanup function?I'm keen to hear your thoughts on whether this could be integrated into Zustand or if there are alternative recommendations for handling cleanup in
subscribe()
.Thanks for considering this! 🚀
Beta Was this translation helpful? Give feedback.
All reactions