T
TanStack3y ago
correct-apricot

Resolve mutation after invalidating queries

const { isSuccess, isLoading, isError, mutate, data, error } = useMutation(
async (e: FormEvent<HTMLFormElement>) => {
e.preventDefault();
//fetching some API here
},
{
onSuccess: () => queryClient.invalidateQueries({ queryKey: ["user"] }),
}
);
const { isSuccess, isLoading, isError, mutate, data, error } = useMutation(
async (e: FormEvent<HTMLFormElement>) => {
e.preventDefault();
//fetching some API here
},
{
onSuccess: () => queryClient.invalidateQueries({ queryKey: ["user"] }),
}
);
Is it possible to have isLoading flag still equals to true, when mutation completed, but invalidatingQueries is in progress?
2 Replies
vicious-gold
vicious-gold3y ago
that's what your code is doing: if you return the promise from invalidateQueries in onSuccess, the mutation will await it before it completes its loading state
correct-apricot
correct-apricotOP3y ago
great, thanks!

Did you find this page helpful?