Skip to content

Commit a62ac21

Browse files
committed
Export types and interfaces. Use built-in types for Fetch API.
1 parent 6745056 commit a62ac21

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/index.d.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import * as React from "react"
22

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>
56

67
export interface AsyncOptions<T> {
78
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>
1011
watch?: any
1112
watchFn?: (props: object, prevProps: object) => any
1213
initialValue?: T
@@ -15,7 +16,7 @@ export interface AsyncOptions<T> {
1516
[prop: string]: any
1617
}
1718

18-
interface AsyncProps<T> extends AsyncOptions<T> {
19+
export interface AsyncProps<T> extends AsyncOptions<T> {
1920
children?: AsyncChildren<T>
2021
}
2122

@@ -62,18 +63,14 @@ export function useAsync<T>(
6263
arg2?: AsyncOptions<T>
6364
): AsyncState<T>
6465

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> {
7167
defer?: boolean
68+
json?: boolean
7269
}
7370

7471
export function useFetch<T>(
75-
input: Request | string,
76-
init?: FetchInit,
72+
input: RequestInfo,
73+
init?: RequestInit,
7774
options?: FetchOptions<T>
7875
): AsyncState<T>
7976

0 commit comments

Comments
 (0)