T
TanStack2y ago
wise-white

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);
},
})
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?
3 Replies
cloudy-cyan
cloudy-cyan2y ago
start the timer in onMutate return it from onMutate then it will be available in onSuccess
flat-fuchsia
flat-fuchsia2y ago
Is this not a feature of the devtools? That could be an interesting addition
wise-white
wise-whiteOP2y ago
Yes I think in devtools we can get the time

Did you find this page helpful?