import { QueryKey , useMutation , UseMutationOptions , UseMutationResult , useQuery , UseQueryOptions , UseQueryResult , } from "react-query" ; import { Functions , httpsCallable , HttpsCallableOptions , } from "firebase/functions" ; export function useFunctionsQuery < RequestData = any , ResponseData = unknown , ModifiedData = ResponseData > ( key , functions , trigger , data ? , options ? , useQueryOptions ? ) { return useQuery < ResponseData , Error , ModifiedData > ( { ... useQueryOptions , queryKey : useQueryOptions ?. queryKey ?? key , async queryFn ( ) { const response = await httpsCallable < RequestData , ResponseData > ( functions , trigger , options ) ( data ) ; return response . data ; } , } ) ; } export function useFunctionsCall < RequestData = any , ResponseData = unknown > ( functions , trigger , options ? , useMutationOptions ? ) { return useMutation < ResponseData , Error , RequestData > ( async ( data ) => { const response = await httpsCallable < RequestData , ResponseData > ( functions , trigger , options ) ( data ) ; return response . data ; } , useMutationOptions ) ; }