Type definition for staleTime function parameters
I have a call to useQuery that if successful returns a StripeOnboardingLinkDto. The Query Key is
["getOnboardingLink", {}]
. How would I capture this in the Query type used for the staleTime function3 Replies
quickest-silver•10mo ago
what are you trying to achieve please?
gradual-turquoiseOP•10mo ago
We have an link expiration time provided from the endpoint, so I don't want to refetch the data until the expires at date is reached.
staleTime: (query: any) => {
const data = query?.state?.data as StripeOnboardingLinkDto || {};
if (data?.expiresAt) {
const difference = getDifferenceBetweenTwoDates(
dayjs(data.expiresAt).format(),
new Date().toISOString()
).milliseconds;
console.log(difference);
return difference;
}
return 0;
}
the type signature I'm aiming for is: (query: Query<TQueryFnData, TError, TData, TQueryKey>) => number
but not sure how to translate the data I'm expecting into this.
quickest-silver•10mo ago
If you inline the function, types will be inferred. If you want to extract it, look at what's inferred and copy that. If you want a generic version, you need 4 type parameters.