Skip to content
Matthias Van Parijs edited this page Oct 17, 2025 · 5 revisions

Interfaces

Options

Defined in: types.ts:29

Options.

Type Parameters

Type Parameter
T

Properties

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

Methods

onError()?

optional onError(error): void

Defined in: types.ts:50

Callback when an error occurs.

Parameters
Parameter Type Description
error unknown
Returns

void

onLoading()?

optional onLoading(): void

Defined in: types.ts:59

Called when the fetcher starts loading data.

Returns

void

onSuccess()?

optional onSuccess(data): void

Defined in: types.ts:55

Callback triggered when the fetcher completes successfully.

Parameters
Parameter Type Description
data T
Returns

void


UseFetchReturn

Defined in: types.ts:85

Return value for useFetch.

Type Parameters

Type Parameter
T

Properties

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

Methods

refetch()

refetch(): void

Defined in: types.ts:102

In case you'd like to manually refetch the data.

Returns

void

Type Aliases

Fetcher()

Fetcher<T, K> = (ctx) => Promise<T>

Defined in: types.ts:4

Fetcher, an async function that resolves or rejects into data.

Type Parameters

Type Parameter
T
K extends Key

Parameters

Parameter Type
ctx FetcherContext<K>

Returns

Promise<T>


FetcherContext

FetcherContext<K> = object

Defined in: types.ts:9

Context given to each fetcher call.

Type Parameters

Type Parameter Default type
K extends Key Key

Properties

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

Key = string | readonly [any, ...unknown[]] | Record<any, any>

Defined in: types.ts:24

Key identifier.


OptionsWithDebounce

OptionsWithDebounce<T> = Options<T> & object

Defined in: types.ts:75

Options, for debounce purposes.

Type Declaration

Name Type Description Defined in
debounceDelay number The debounce delay, in seconds. types.ts:79

Type Parameters

Type Parameter
T

OptionsWithInitialData

OptionsWithInitialData<T> = Options<T> & object

Defined in: types.ts:65

Options, with initial data defined.

Type Declaration

Name Type Description Defined in
initialData T Mandatory initial data. types.ts:69

Type Parameters

Type Parameter
T

Functions

useFetch()

Internal

Call Signature

useFetch<T, K>(fetcher, key, options): UseFetchReturn<T>

Defined in: use-fetch.tsx:21

useFetch with initial data provided.

Type Parameters
Type Parameter Description
T Type of the data to fetch.
K extends Key Type of the key used for fetching.
Parameters
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.
Returns

UseFetchReturn<T>

The fetch result with guaranteed data type T.

Call Signature

useFetch<T, K>(fetcher, key, options?): UseFetchReturn<T | null>

Defined in: use-fetch.tsx:37

useFetch without initial data.

Type Parameters
Type Parameter Description
T Type of the data to fetch.
K extends Key Type of the key used for fetching.
Parameters
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.
Returns

UseFetchReturn<T | null>

The fetch result with type T or null if data is not yet loaded.


useFetchDebounced()

useFetchDebounced<T, K>(fetcher, key, options): UseFetchReturn<T | null>

Defined in: use-fetch-debounced.ts:13

Debounced fetch data.

Type Parameters

Type Parameter
T
K extends Key

Parameters

Parameter Type Description
fetcher Fetcher<T, K>
key K
options OptionsWithDebounce<T>

Returns

UseFetchReturn<T | null>