useFetch
Function: useFetch()
Section titled “Function: 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.
Type Parameters
Section titled “Type Parameters”T
Expected response type
Parameters
Section titled “Parameters”client
Section titled “client”Client instance from createClient
string
Request path (relative or absolute)
options?
Section titled “options?”UseFetchOptions<T> = {}
Request options including enabled and deps
Returns
Section titled “Returns”Example
Section titled “Example”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!} />;