Skip to content
API/useQubeeList()

useQubeeList()

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

Drive 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 { useQubeeList } from '@qubeejs/react';
function useQubeeList<TList extends ListDefinition<ListParams, {}>>(list: TList, ...args: QubeeListArgs<TList>): QubeeListHandle<TList>
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.

The state, request, pending flag, and the functions that change them

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>
// /projects/42/tasks?status=open — the project comes from the path, the rest from the query
const { projectId } = useParams<{ projectId: string }>();
const tasks = useQubeeList(taskList, projectId ? { projectId } : null);

QubeeListArgs · QubeeListHandle