React overview
Pass a request to a hook, get typed data, error and loading state back. No query keys or fetcher functions: the request you defined with core already knows its endpoint, types and cache key.
import { useFetch } from "@hyper-fetch/react";
import { getUsers } from "./api/users";
export const Users = () => {
const { data, loading, error } = useFetch(getUsers);
if (loading && !data) return <p>Loading...</p>;
if (error) return <p>{error.message}</p>;
return <ul>{data?.map((user) => <li key={user.id}>{user.name}</li>)}</ul>;
};
data is typed as User[] | null from the request, so the hook needs no generics. The hooks need React 18 or later.
- Request
Defined once, at module level
- Hook
Sends and subscribes
- Cache
One entry, shared by every hook
- Component
Re-renders on the fields it reads
The hooks
Load data on mount and when the request changes.
useSubmitCreate, update or delete on demand with submit().
useInfiniteFetchLoad more pages for infinite scroll.
useStreamRender a streamed response, such as LLM output.
useCacheRead and change a cache entry without a request.
useQueueShow and control the requests waiting in a queue.
useIsFetchingDrive a global loading indicator.
useAppManagerReact to focus and online state.
useListenersocketsReceive realtime messages of a topic.
useEmittersocketsSend realtime messages and read the connection state.
useLiveQuerydbQuery a local collection that stays in sync.
HydrateSSRPass server-rendered responses to the first render.
Global defaults
Hooks work without a provider. Add <Provider> when every hook should share options, such as refetching when the
window regains focus. Options passed to a hook always win. The
config provider guide shows the setup.
Common tasks
From fetch and useEffect to useFetch, step by step.
SubmittingForms, mutations and refreshing lists after a save.
Optimistic updatesShow the change first, roll back on failure.
Infinite scrollPage, offset or cursor lists with useInfiniteFetch.
Next.jsFetch on the server and hydrate the first render.
Refetch on focusKeep data fresh when the user comes back.
Next
A user list and a form with useFetch and useSubmit.
Basic data fetchingexampleA list and its details, runnable in StackBlitz.
CRUDexampleCreate, update and delete, written into the cached list.
React NativeThe same hooks, with NetInfo and AppState wired in.
ElectronRuns in the renderer, with online and focus from main.
HyperFlow devtoolsWatch your hooks' requests, cache and queues live.