-
Notifications
You must be signed in to change notification settings - Fork 2
API
Defined in: types.ts:29
Options.
Type Parameter |
---|
T |
Property | Type | Description | Defined in |
---|---|---|---|
fetchOnMount?
|
boolean |
When initialData is defined, the first render is skipped since the data is already available. If you prefer not to skip the initial render, enable this option. When initialData is undefined, this setting has no effect. | types.ts:41 |
initialData?
|
T |
Initial data. When provided, the data will no longer be nullable and will use this value instead. This is especially useful when passing data from the server to the client (eg; with RSC or SSR) to prepopulate the hook. | types.ts:35 |
refetchInterval?
|
number |
Refetches the data periodically, using the given interval in seconds. | types.ts:45 |
optional
onError(error
):void
Defined in: types.ts:50
Callback when an error occurs.
Parameter | Type | Description |
---|---|---|
error |
unknown |
void
optional
onLoading():void
Defined in: types.ts:59
Called when the fetcher starts loading data.
void
optional
onSuccess(data
):void
Defined in: types.ts:55
Callback triggered when the fetcher completes successfully.
Parameter | Type | Description |
---|---|---|
data |
T |
void
Defined in: types.ts:85
Return value for useFetch.
Type Parameter |
---|
T |
Property | Type | Description | Defined in |
---|---|---|---|
data
|
T |
The last result of the fetcher. | types.ts:89 |
error
|
unknown |
An error occured, will be cleared when the fetcher runs a second time. | types.ts:94 |
isLoading
|
boolean |
Whether the fetcher is executing. | types.ts:98 |
refetch():
void
Defined in: types.ts:102
In case you'd like to manually refetch the data.
void
Fetcher<
T
,K
> = (ctx
) =>Promise
<T
>
Defined in: types.ts:4
Fetcher, an async function that resolves or rejects into data.
Type Parameter |
---|
T |
K extends Key
|
Parameter | Type |
---|---|
ctx |
FetcherContext <K > |
Promise
<T
>
FetcherContext<
K
> =object
Defined in: types.ts:9
Context given to each fetcher call.
Type Parameter | Default type |
---|---|
K extends Key
|
Key |
Property | Type | Description | Defined in |
---|---|---|---|
key
|
K |
The currently active key. | types.ts:13 |
signal
|
AbortSignal |
You can use the signal to implement abort logic in your fetcher. A pending fetcher call will be aborted when new data is about to be fetched. | types.ts:18 |
Key =
string
| readonly [any
,...unknown[]
] |Record
<any
,any
>
Defined in: types.ts:24
Key identifier.
OptionsWithDebounce<
T
> =Options
<T
> &object
Defined in: types.ts:75
Options, for debounce purposes.
Name | Type | Description | Defined in |
---|---|---|---|
debounceDelay |
number |
The debounce delay, in seconds. | types.ts:79 |
Type Parameter |
---|
T |
OptionsWithInitialData<
T
> =Options
<T
> &object
Defined in: types.ts:65
Options, with initial data defined.
Name | Type | Description | Defined in |
---|---|---|---|
initialData |
T |
Mandatory initial data. | types.ts:69 |
Type Parameter |
---|
T |
Internal
useFetch<
T
,K
>(fetcher
,key
,options
):UseFetchReturn
<T
>
Defined in: use-fetch.tsx:21
useFetch with initial data provided.
Type Parameter | Description |
---|---|
T |
Type of the data to fetch. |
K extends Key
|
Type of the key used for fetching. |
Parameter | Type | Description |
---|---|---|
fetcher |
Fetcher <T , K > |
Function that fetches the data. |
key |
K |
The key associated with the fetch request. |
options |
OptionsWithInitialData <T > |
Options including initial data. |
The fetch result with guaranteed data type T.
useFetch<
T
,K
>(fetcher
,key
,options?
):UseFetchReturn
<T
|null
>
Defined in: use-fetch.tsx:37
useFetch without initial data.
Type Parameter | Description |
---|---|
T |
Type of the data to fetch. |
K extends Key
|
Type of the key used for fetching. |
Parameter | Type | Description |
---|---|---|
fetcher |
Fetcher <T , K > |
Function that fetches the data. |
key |
K |
The key associated with the fetch request. |
options? |
Options <T > |
Optional fetch options. |
UseFetchReturn
<T
| null
>
The fetch result with type T or null if data is not yet loaded.
useFetchDebounced<
T
,K
>(fetcher
,key
,options
):UseFetchReturn
<T
|null
>
Defined in: use-fetch-debounced.ts:13
Debounced fetch data.
Type Parameter |
---|
T |
K extends Key
|
Parameter | Type | Description |
---|---|---|
fetcher |
Fetcher <T , K > |
|
key |
K |
|
options |
OptionsWithDebounce <T > |
UseFetchReturn
<T
| null
>