useQubeeSWR()
hookFetch the page a request asks for through SWR.
It is useSWR with the key ['qubee', uri, headers], a fetcher that calls
fetchQubeePage, and keepPreviousData on, so the previous page stays while the next
one loads. Everything else is SWR’s: its cache, de-duplication, revalidation and mutate.
Pass list.request from useQubeeList: it follows the committed state, so the key
changes once per navigation, never per keystroke. What performs the request is the fetcher
option, else the nearest QubeeFetchProvider’s, else the global fetch.
A null request fetches nothing and shows no page — or the fallbackData you gave it — as with
useQubeeQuery: keepPreviousData keeps a page while the next request loads, never
across a null one. The request that follows a null one shows no page from before it until
it has a page of its own in SWR’s cache; if it fails instead, the next request does not keep it
either.
Import
Section titled “Import”import { useQubeeSWR } from '@qubeejs/react/swr';Signature
Section titled “Signature”function useQubeeSWR<T extends object>(request: ListRequest | null, options: QubeeSWROptions<T>): SWRResponse<PaginatedResult<T>, Error>Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
request |
ListRequest | null |
The page to fetch; null fetches nothing |
options |
QubeeSWROptions<T> |
SWR’s configuration, with fetcher a QubeeFetcher |
Returns
Section titled “Returns”What useSWR returns, with data typed as core’s PaginatedResult<T>
Example
Section titled “Example”const list = useQubeeList(articleList);const { data, error, isValidating } = useQubeeSWR<Article>(list.request);