Skip to content
Introduction/Quick start

Quick start

This page builds an article list backed by a Strapi API. Its query lives in the address bar — /articles?q=react&status=published&sort=title&page=2 — so a reload, a shared link and the back button all show the same list.

A list is declared once, with defineList from @qubeejs/core: the driver, the resource, the URL parameters it owns, and how its state becomes a query. Declare it at module level, in a file that both your pages and your components import.

src/articles/article-list.ts
import {
defineList,
enumParam,
FilterOperatorEnum,
integerParam,
SortEnum,
sortParam,
STRAPI_DRIVER,
stringParam,
} from '@qubeejs/core';
/** The API every example on this site talks to. */
export const API_URL = 'https://example.com/api';
/** An article's publication status, as the API spells it. */
export enum ArticleStatusEnum {
DRAFT = 'draft',
PUBLISHED = 'published',
}
/** An article as the Strapi API returns it. */
export type Article = {
id: number;
publishedAt: string;
status: ArticleStatusEnum;
title: string;
};
/**
* The article list. Its query is the page URL —
* `/articles?q=react&status=published&sort=title&page=2` — with the params in
* the order they are declared.
*/
export const articleList = defineList({
qubee: { baseUrl: API_URL, driver: STRAPI_DRIVER },
resource: 'articles',
params: {
// Kept exactly as typed (stringParam does not trim), because a search box
// shows it while the user types. apply() trims it on the way to the API.
q: stringParam('q'),
status: enumParam('status', ArticleStatusEnum),
sort: sortParam('sort', {
default: [{ field: 'publishedAt', order: SortEnum.DESC }],
fields: ['publishedAt', 'title'],
}),
page: integerParam('page', { default: 1, min: 1 }),
},
apply: (builder, { q, sort, status }) => {
const search = q?.trim();
builder.setLimit(20);
sort.forEach(({ field, order }) => builder.addSort(field, order));
if (search) {
builder.addFilterOperator('title', FilterOperatorEnum.ILIKE, search);
}
if (status) {
builder.addFilter('status', status);
}
},
});
  • Values are typed from the declaration. page and sort have defaults, so they are always a number and a list of sorts; q and status have none, so they may be undefined.
  • The order of params is the order in the URL.
  • q is kept exactly as typed, because a search box shows it while the user types; apply trims it on the way to the API. Search, debounce & pending state explains why that matters.

Every param, and the rules the URL follows, are documented with the core: Lists & URL state ↗.

A list reads and writes the URL through your router. Say which one, once, at the root:

src/main.tsx
import { BrowserAdapter } from '@qubeejs/react';
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import { App } from './app';
const root = document.getElementById('root');
if (!root) {
throw new Error('index.html has no #root element');
}
// Every list below the provider reads and writes the URL through browser history.
createRoot(root).render(
<StrictMode>
<BrowserAdapter>
<App />
</BrowserAdapter>
</StrictMode>
);

<BrowserAdapter> is for an app without a router library. With one, use its adapter instead — React Router, TanStack Router or Next.js — and the rest of this page stays the same.

useQubeeList reads the URL into typed state and gives back the request for the page to show; useQubeeQuery fetches that request and parses the answer with the driver that built it.

src/articles/articles-page.tsx
import { useQubeeList, useQubeeQuery } from '@qubeejs/react';
import { type Article, articleList, ArticleStatusEnum } from './article-list';
/** How long typing must pause before the URL changes. */
const SEARCH_DEBOUNCE_MS = 300;
/**
* Articles, searched, filtered, sorted and paged through the URL. The component names no router:
* the list takes its adapter from the provider at the root.
*/
export function ArticlesPage() {
const list = useQubeeList(articleList);
const articles = useQubeeQuery<Article>(list.request);
const { state } = list;
const lastPage = articles.data?.lastPage ?? 1;
return (
<main aria-busy={list.isPending || articles.isFetching}>
<input
aria-label="Search articles"
onChange={(event) =>
list.set({ q: event.target.value }, { debounce: SEARCH_DEBOUNCE_MS, replace: true })
}
type="search"
value={state.q ?? ''}
/>
<label>
<input
checked={state.status === ArticleStatusEnum.PUBLISHED}
onChange={(event) =>
list.set({ status: event.target.checked ? ArticleStatusEnum.PUBLISHED : undefined })
}
type="checkbox"
/>
Published only
</label>
<button onClick={() => list.toggleSort('title')} type="button">
Sort by title
</button>
{articles.error && <p role="alert">The articles could not be loaded.</p>}
<ul>
{articles.data?.data.map((article) => (
<li key={article.id}>{article.title}</li>
))}
</ul>
<button disabled={state.page <= 1} onClick={() => list.setPage(state.page - 1)} type="button">
Previous
</button>
<button
disabled={state.page >= lastPage}
onClick={() => list.setPage(state.page + 1)}
type="button"
>
Next
</button>
</main>
);
}

What happens when someone types react into the search box:

  1. set({ q: 'react' }, { debounce: 300, replace: true }) updates state.q at once, so the input never lags behind the typing.
  2. 300 ms after the last keystroke, the adapter navigates once, to /articles?q=react, replacing the history entry instead of adding one per keystroke. The page goes back to 1: a new search makes the old page number meaningless.
  3. request changes — its uri now filters on the title — and useQubeeQuery fetches the new page. The rows of the old one stay on screen until it arrives.
  • Setup — the same page on your router, with its links.
  • Lists in the URL — every member of useQubeeList, and the three layers of state behind it.
  • Fetching — your own fetcher, errors, fetching on the server, and caching with TanStack Query or SWR.
  • Lists in memory — the same list in a dialog, without the URL.