useQubeeList()
hookDrive a declared list: its state lives in the page URL, or wherever its router adapter keeps it.
state updates synchronously on every set(), so a controlled input never lags behind a
debounce; request follows the committed state, so a cache key built from it changes once per
navigation, never per keystroke; the URL stays the source of truth — a change the hook did not
cause (Back, Forward, a link elsewhere) cancels a pending debounce and discards anything not
yet in the URL. Unmounting (or hiding the tree with <Activity>) cancels a pending debounce and
drops its draft too. A click on a link while a debounce waits commits it at once, so the link
the user follows is never overtaken by it. toggleSort is there when the list declares exactly
one sortParam.
A list that declares an input — what its request needs besides URL state, such as a project id
from the route path — takes it after the list: useQubeeList(taskList, { projectId }). The input
goes into request and never into the URL. null means it is not ready yet, a lookup still in
flight or a route param missing: request is then null, and the fetching hooks fetch nothing.
A new input object with the same values keeps the same request.
The list reads and writes the URL through a router adapter: the one passed last, else the
nearest adapter provider’s — BrowserAdapter, or the one for your router.
Import
Section titled “Import”import { useQubeeList } from '@qubeejs/react';Signature
Section titled “Signature”function useQubeeList<TList extends ListDefinition<ListParams, {}>>(list: TList, ...args: QubeeListArgs<TList>): QubeeListHandle<TList>Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
list |
TList |
A list declared once with defineList, as a module-level constant |
args |
QubeeListArgs<TList> |
[adapter?] for a list without an input, [input, adapter?] for a list that declares one — see QubeeListArgs. The adapter takes the place of the nearest provider’s: the current location and a navigate, rebuilt every render. An input must not be an object with a function navigate: with one argument after the list, that is read as the adapter. |
Returns
Section titled “Returns”The state, request, pending flag, and the functions that change them
Example
Section titled “Example”const list = useQubeeList(articleList);
<input value={list.state.q ?? ''} onChange={(e) => list.set({ q: e.target.value }, { debounce: 300, replace: true })} /><th aria-sort={getAriaSort(list.state.sort, 'title')} onClick={() => list.toggleSort('title')}>Title</th><a href={list.href({ page: 2 })}>2</a>Example
Section titled “Example”// /projects/42/tasks?status=open — the project comes from the path, the rest from the queryconst { projectId } = useParams<{ projectId: string }>();const tasks = useQubeeList(taskList, projectId ? { projectId } : null);