useQubeeQuery()
hookFetch 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
Section titled “Import”import { useQubeeQuery } from '@qubeejs/react';Signature
Section titled “Signature”function useQubeeQuery<T extends object>(request: ListRequest | null, options: QubeeQueryOptions<T>): QubeeQueryResult<T>Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
request |
ListRequest | null |
The page to fetch; null fetches nothing |
options |
QubeeQueryOptions<T> |
enabled, fetcher, initialData, keepPreviousData |
Returns
Section titled “Returns”The page, the error, the two loading flags and refetch
Example
Section titled “Example”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>