Skip to content

useQuery callbacks don't run after unmount, useMutation callbacks do #5133

Answered by TkDodo
vincerubinetti asked this question in General
Discussion options

You must be logged in to vote

useQuery callbacks are observer level callbacks, so they are the same as callbacks on .mutate. They are thus bound to the lifecycle of components they are mounted in.

useMutation callbacks are the "exception" here, because they always run.

For global callbacks, you'd want the global cache level callbacks, because, again, the callbacks on useQuery are observer level callbacks, which means if you call useQuery twice (e.g. via a custom hook), onSuccess will also be called twice, showing two notification.

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
1 reply
@vincerubinetti
Comment options

Answer selected by vincerubinetti
Comment options

You must be logged in to vote
4 replies
@TkDodo
Comment options

@TkDodo
Comment options

@lehnerchristian
Comment options

@TkDodo
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants