T
TanStack3y ago
equal-aqua

Get a specific mutation based on filters or predicate

I would like to retrieve specific in-flight mutations. I guess I have to do something like queryClient.getMutationCache().getAll().filter( callback )? And in the callback remember to filter by isLoading/isPending as well as the actual predicate I want to match mutations against. queryClient.isMutating allows you to supply a callback to filter the existing mutations, and returns the number of matching mutations which are currently pending (is that correct?). Is there a reason isMutating returns a number instead of an array of in-flight mutations matching the filters? You can always do array.length if you need the number anyway.
5 Replies
equal-aqua
equal-aquaOP3y ago
Looks like there is an undocumented findAll method which helps a little.
other-emerald
other-emerald3y ago
v5 has the useMutationState hook for that without a hook, you are not subscribed to changes isMutating is used by useIsMutating(), which is the hook for it
equal-aqua
equal-aquaOP3y ago
Is there any way to subscribe to changes for a specific mutation by filter or predicate in v4?
other-emerald
other-emerald3y ago
mutationCache.subscribe , then filter things down on your own
equal-aqua
equal-aquaOP3y ago
Thank you!

Did you find this page helpful?