1
1
import * as React from "react"
2
2
3
- type AsyncChildren < T > = ( ( state : AsyncState < T > ) => React . ReactNode ) | React . ReactNode
4
- type PromiseFn < T > = ( props : object ) => Promise < T >
3
+ export type AsyncChildren < T > = ( ( state : AsyncState < T > ) => React . ReactNode ) | React . ReactNode
4
+ export type PromiseFn < T > = ( props : object , controller : AbortController ) => Promise < T >
5
+ export type DeferFn < T > = ( args : any [ ] , props : object , controller : AbortController ) => Promise < T >
5
6
6
7
export interface AsyncOptions < T > {
7
8
promise ?: Promise < T >
8
- promiseFn ?: ( props : object , controller : AbortController ) => Promise < T >
9
- deferFn ?: ( args : any [ ] , props : object , controller : AbortController ) => Promise < T >
9
+ promiseFn ?: PromiseFn < T >
10
+ deferFn ?: DeferFn < T >
10
11
watch ?: any
11
12
watchFn ?: ( props : object , prevProps : object ) => any
12
13
initialValue ?: T
@@ -15,7 +16,7 @@ export interface AsyncOptions<T> {
15
16
[ prop : string ] : any
16
17
}
17
18
18
- interface AsyncProps < T > extends AsyncOptions < T > {
19
+ export interface AsyncProps < T > extends AsyncOptions < T > {
19
20
children ?: AsyncChildren < T >
20
21
}
21
22
@@ -62,18 +63,14 @@ export function useAsync<T>(
62
63
arg2 ?: AsyncOptions < T >
63
64
) : AsyncState < T >
64
65
65
- interface FetchInit {
66
- method ?: string
67
- headers ?: Headers | object
68
- }
69
-
70
- interface FetchOptions < T > extends AsyncOptions < T > {
66
+ export interface FetchOptions < T > extends AsyncOptions < T > {
71
67
defer ?: boolean
68
+ json ?: boolean
72
69
}
73
70
74
71
export function useFetch < T > (
75
- input : Request | string ,
76
- init ?: FetchInit ,
72
+ input : RequestInfo ,
73
+ init ?: RequestInit ,
77
74
options ?: FetchOptions < T >
78
75
) : AsyncState < T >
79
76
0 commit comments