Skip to content

useFetch

useFetch<T>(client, path, options?): UseFetchState<T>

Defined in: packages/fetch-kit/src/react/use-fetch.ts:46

React hook for declarative GET requests.

The in-flight request is automatically aborted if the component unmounts or if deps change before it completes, and stale responses are dropped on the floor rather than racing the latest one into state. State updates are skipped after unmount to avoid React warnings.

T

Expected response type

Client

Client instance from createClient

string

Request path (relative or absolute)

UseFetchOptions<T> = {}

Request options including enabled and deps

UseFetchState<T>

const { data, error, loading, refetch } = useFetch<User>(api, "/users/me");
if (loading) return <Spinner />;
if (error) return <Error error={error} onRetry={refetch} />;
return <Profile user={data!} />;