Skip to main content
Version: v8.0.0

UseFetchOptionsType


Import
import { UseFetchOptionsType } from "@hyper-fetch/react"

Preview​

type UseFetchOptionsType<R,TSelected> = { bounce?: boolean; deepCompare?: (boolean | typeof isEqual); dependencies?: any[]; dependencyTracking?: boolean; disabled?: boolean; initialResponse?: NullableType<Partial<ExtractAdapterResolvedType<R>>>; keepPreviousData?: (auto | preserve | clean); refetchBlurred?: boolean; refetchOnBlur?: boolean; refetchOnFocus?: boolean; refetchOnReconnect?: boolean; refresh?: boolean; refreshTime?: number; revalidate?: boolean; select?: UseTrackedStateSelect<R, TSelected>; structuralSharing?: boolean; suspense?: boolean; throwOnError?: (boolean | (error: ExtractErrorType<R>) => boolean) } & ({ bounceTime?: number; bounceTimeout?: void; bounceType?: debounce } | { bounceTime?: number; bounceTimeout?: number; bounceType: throttle });

Structure​

UseFetchOptionsType
NameTypeDescription
bounce
boolean

Enable/disable debouncing for often changing keys or refreshing, to limit requests to server.

deepCompare
boolean | typeof isEqual

Deep comparison function for hook to check for equality in incoming data, to limit rerenders.

dependencies
any[]

Refetch dependencies

dependencyTracking
boolean

If true it will rerender only when values used by our component gets changed. Otherwise it will rerender on any change.

disabled
boolean

Disable fetching

initialResponse
NullableType<Partial<ExtractAdapterResolvedType<R>>>

If cache is empty we can use placeholder data.

keepPreviousData
auto | preserve | clean

Controls what happens to the current state when the cache key changes (e.g. params or query params change).

  • "auto" (default) — Smart mode: clears state when URL params change (different resource), preserves state when only query params change (pagination/filtering).
  • "preserve" — Always keeps previous data visible until new data arrives.
  • "clean" — Always resets state to initial values when cache key changes.
refetchBlurred
boolean

Enable/disable data refresh if our tab is not focused(used by user at given time).

refetchOnBlur
boolean

Enable/disable data refresh if user leaves current tab.

refetchOnFocus
boolean

Enable/disable data refresh if user enters current tab.

refetchOnReconnect
boolean

Enable/disable data refresh if network is restored.

refresh
boolean

Enable/disable refresh data

refreshTime
number

Refresh data interval time

revalidate
boolean

If true it will refetch data in background no matter if we have it from cache.

structuralSharing
boolean

Keep references of the unchanged parts of the selected data between updates (default true).

suspense
boolean

Enable React Suspense mode. When true, the hook throws a Promise while loading, which is caught by the nearest Suspense boundary. The component re-renders with data available once the request resolves.

throwOnError
boolean | (error: ExtractErrorType<R>) => boolean

Throw the request error to the closest React Error Boundary once the request settles with an error. Pass a function to decide per error.

select
UseTrackedStateSelect<R, TSelected>

Pick or transform the part of the response data used by the component. The hook rerenders only when the selected value changes, while the cache stays shared with other hooks.