TanStackT
TanStack7mo ago
9 replies
sacred-rose

Is it possible to wait for a few seconds before invalidates the cache in onSuccess?

I have tried this, but it does not work as I expect
useMutation({
    mutationFn: fetchData,
    onSuccess: async () => {
      await sleep(3000);
      return queryClient.invalidateQueries({
        queryKey: ["users", id],
      });
    },
  });
Was this page helpful?