@@ -171,7 +171,7 @@ export interface UseLazyApiOptions<
171171 cached ?: boolean
172172 refetchOnFocus ?: boolean
173173 variables ?: TVariables
174- onFetch ?: ( ) => Promise < any >
174+ onFetch ?: ( ) => any
175175 onCompleted ?: ( params : OnCompletedParams < T , TData , TError , TVariables , K > ) => any
176176}
177177
@@ -334,6 +334,7 @@ function createUseApi<
334334 TApiVariables extends TVariables [ K ]
335335 > ( key : K , opts : UseApiOptions < T , TData , TError , TVariables , K > = { } ) {
336336 const { cache } = useContext ( ctx )
337+ const optsRef = useValueRef ( opts )
337338 const {
338339 skip = false ,
339340 force = false ,
@@ -350,9 +351,11 @@ function createUseApi<
350351 const onFetch = useCallback ( async ( ) => {
351352 calledRef . current = true
352353 loadingRef . current = true
354+ if ( optsRef . current . onFetch ) await optsRef . current . onFetch ( )
353355 } , [ ] )
354- const onCompleted = useCallback ( async ( ) => {
356+ const onCompleted = useCallback ( async ( params : OnCompletedParams < T , TData , TError , TVariables , K > ) => {
355357 loadingRef . current = false
358+ if ( optsRef . current . onCompleted ) await optsRef . current . onCompleted ( params )
356359 } , [ ] )
357360 const [ fetch , result ] = useLazyApi < K , TApiData , TApiError , TApiVariables > ( key , {
358361 ...lazyOpts ,
0 commit comments