TanStackT
TanStack2y ago
3 replies
abstract-purple

Calculating the total time taken for mutation

Hi I have a function for mutation, and I want to know the total time taken for the function to execute.
That is, the difference between the time from onSuccess and start of the function.

Currently what I am doing is returning the start time from the mutation function and accessing it in the data on onSuccess function,

Something like on :
useMutation<number | undefined, Error, void, number | undefined>({
    mutationFn: callFunction,
    onSuccess: (data: number | undefined) => {
      console.log(data);
    },
  })


Is there any better way to handle this or can we access the total time taken or something?
Was this page helpful?