31 lines
616 B
TypeScript
31 lines
616 B
TypeScript
import {
|
|
QueryClient,
|
|
QueryKey,
|
|
UseMutationOptions,
|
|
} from "@tanstack/react-query"
|
|
|
|
export const buildOptions = <
|
|
TData,
|
|
TError,
|
|
TVariables,
|
|
TContext,
|
|
TKey extends QueryKey
|
|
>(
|
|
queryClient: QueryClient,
|
|
queryKey?: TKey,
|
|
options?: UseMutationOptions<TData, TError, TVariables, TContext>
|
|
): UseMutationOptions<TData, TError, TVariables, TContext> => {
|
|
return {
|
|
...options,
|
|
onSuccess: (...args) => {
|
|
if (options?.onSuccess) {
|
|
return options.onSuccess(...args)
|
|
}
|
|
|
|
if (queryKey !== undefined) {
|
|
queryClient.invalidateQueries(queryKey)
|
|
}
|
|
},
|
|
}
|
|
}
|