Skip to content
API/useTanStackRouterAdapter()

useTanStackRouterAdapter()

hook
src/hooks/use-tanstack-router-adapter.ts1 parameter

TanStack Router as a RouterAdapter: its location in, its navigate out.

It reads the query string as TanStack Router serialised it and navigates with whole hrefs, so a basepath or a rewrite is honoured. The router’s search serialisers run in both directions: its default pair re-types JSON-looking values (1.50 becomes 1.5, 10 becomes 10), and the list settles on what the router wrote. Call it inside a TanStack Router tree. Pass the result to useQubeeList for one list, or wrap the routes in TanStackRouterAdapter and every list below finds it.

A list navigation keeps the scroll position: TanStack Router would otherwise scroll to the top each time a filter or a page number changes.

import { useTanStackRouterAdapter } from '@qubeejs/react/tanstack-router';
function useTanStackRouterAdapter(options: TanStackRouterAdapterOptions): RouterAdapter
Parameter Type Description
options TanStackRouterAdapterOptions scroll: scroll to the top on navigation; false by default

The current pathname and query, and a navigate that goes through TanStack Router

function Articles(): ReactElement {
const list = useQubeeList(articleList, useTanStackRouterAdapter());
return <button onClick={() => list.setPage(2)}>2</button>;
}

RouterAdapter · TanStackRouterAdapterOptions