@@ -281,32 +281,40 @@ const useAsyncFetch = <T extends {}>(
281
281
init,
282
282
isDefer,
283
283
} )
284
- const state = useAsync ( {
285
- ...options ,
286
- [ fn ] : useCallback (
287
- // TODO
288
- ( arg1 : any , arg2 : any , arg3 : any ) => {
289
- const [ override , signal ] = arg3 ? [ arg1 [ 0 ] , arg3 . signal ] : [ undefined , arg2 . signal ]
290
- if ( typeof override === "object" && "preventDefault" in override ) {
291
- // Don't spread Events or SyntheticEvents
292
- return doFetch ( input , {
284
+ const promiseFn = useCallback (
285
+ ( _ : AsyncOptions < T > , { signal } : AbortController ) => {
286
+ return doFetch ( input , {
287
+ signal,
288
+ ...init ,
289
+ } )
290
+ } ,
291
+ [ identity ] // eslint-disable-line react-hooks/exhaustive-deps
292
+ )
293
+ const deferFn = useCallback (
294
+ ( [ override ] : any [ ] , _ : AsyncOptions < T > , { signal } : AbortController ) => {
295
+ if ( typeof override === "object" && "preventDefault" in override ) {
296
+ // Don't spread Events or SyntheticEvents
297
+ return doFetch ( input , {
298
+ signal,
299
+ ...init ,
300
+ } )
301
+ }
302
+ return typeof override === "function"
303
+ ? doFetch ( input , {
304
+ signal,
305
+ ...override ( init ) ,
306
+ } )
307
+ : doFetch ( input , {
293
308
signal,
294
309
...init ,
310
+ ...override ,
295
311
} )
296
- }
297
- return typeof override === "function"
298
- ? doFetch ( input , {
299
- signal,
300
- ...override ( init ) ,
301
- } )
302
- : doFetch ( input , {
303
- signal,
304
- ...init ,
305
- ...override ,
306
- } )
307
- } ,
308
- [ identity ] // eslint-disable-line react-hooks/exhaustive-deps
309
- ) ,
312
+ } ,
313
+ [ identity ] // eslint-disable-line react-hooks/exhaustive-deps
314
+ )
315
+ const state = useAsync ( {
316
+ ...options ,
317
+ [ fn ] : isDefer ? deferFn : promiseFn ,
310
318
} )
311
319
useDebugValue ( state , ( { counter, status } ) => `[${ counter } ] ${ status } ` )
312
320
return state
0 commit comments