Skip to content
API/useQubeeQuery()

useQubeeQuery()

hook
src/hooks/use-qubee-query.ts2 parameters

Fetch the page a request asks for, and fetch again when the request changes.

Pass list.request from useQubeeList: it follows the committed state, so the hook fetches once per navigation, never per keystroke. A request is identified by its address and its headers, not by object identity. When it changes, the request it replaces is aborted and its answer, if one still arrives, is ignored; an abort is never an error. Unmounting aborts too.

While the next page loads, data is the previous page. A failure sets error and discards the data, so a page is never shown under another request’s state. isFetching is true from the first render when a fetch is due — on the server too, where nothing is fetched — so the server’s HTML and the client’s first render agree.

It keeps no cache and shares nothing between components: two components that fetch the same request fetch twice. Call it once and pass the result down, or use the TanStack Query or SWR entry.

import { useQubeeQuery } from '@qubeejs/react';
function useQubeeQuery<T extends object>(request: ListRequest | null, options: QubeeQueryOptions<T>): QubeeQueryResult<T>
Parameter Type Description
request ListRequest | null The page to fetch; null fetches nothing
options QubeeQueryOptions<T> enabled, fetcher, initialData, keepPreviousData

The page, the error, the two loading flags and refetch

const list = useQubeeList(articleList);
const articles = useQubeeQuery<Article>(list.request);
<ul aria-busy={list.isPending || articles.isFetching}>
{articles.data?.data.map((article) => <li key={article.id}>{article.title}</li>)}
</ul>

QubeeQueryOptions · QubeeQueryResult