useQueryStates
function useQueryStates<M>(parsers, options?): readonly [inferParserMapType<M>, SetValues<M>];Defined in: tanstack/react/use-query-states.ts:59
Like useQueryState, but for several keys that move together. All keys
update atomically in a single URL commit; unmanaged params are preserved;
passing null clears every managed key.
The setter takes a partial object (only the keys present are written; a
key set to null is removed), null, or an updater receiving all current
values. options.urlKeys maps state keys to shorter URL keys; the other
options apply to every key.
Options resolve per key: per-call > that key’s parser .withOptions() >
hook options > adapter defaults. Each written key uses its own
clearOnDefault; the single URL commit merges the keys’ options the way
same-tick updates merge (push beats replace, a full navigation beats
shallow, the strongest rate limit wins).
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
M extends ParserMap |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
parsers |
M |
options? |
UseQueryStatesOptions<M> |
Returns
Section titled “Returns”readonly [inferParserMapType<M>, SetValues<M>]
Example
Section titled “Example”import { parseAsIndex, parseAsString, useQueryStates } from "@xtandard/lib/tanstack";
const tableSearch = { pageIndex: parseAsIndex.withDefault(0), sort: parseAsString.withDefault("createdAt"),};
function Table() { // ?page=2&sort=name → { pageIndex: 1, sort: "name" } const [{ pageIndex, sort }, setSearch] = useQueryStates(tableSearch, { urlKeys: { pageIndex: "page" }, }); // setSearch({ sort: "email", pageIndex: 0 }) → one commit: ?sort=email // setSearch(null) → removes page and sort, keeps other params}