T
TanStack12mo ago
adverse-sapphire

l Query Revalidation Completes After Mutation

Hey! I've globally set up my MutationCache like this:
mutationCache: new MutationCache({
onSuccess: (data) => {
if ('message' in data) {
toast.success(data.message);
queryClient.invalidateQueries();
}
}
});
mutationCache: new MutationCache({
onSuccess: (data) => {
if ('message' in data) {
toast.success(data.message);
queryClient.invalidateQueries();
}
}
});
Now, in another component, I have an edit form that triggers a mutation inside a popup. The issue is that the popup closes immediately after the mutation, but revalidating (with invalidateQueries) takes some time before the list gets updated. Do you know if there's any way I can check if queryClient.invalidateQueries(); is still in progress? I’d like to prevent the popup from closing until revalidation is complete. Thanks!
1 Reply
quickest-silver
quickest-silver12mo ago
You can return the promise from invalidateQueries, then the mutation will stay in pending state until the invalidation is complete

Did you find this page helpful?