Skip to content

@xtandard/lib/tanstack

nuqs-style typed URL query state for TanStack Router (peers react, @tanstack/react-router).

import { … } from "@xtandard/lib/tanstack";
Name Summary
createQueryStateStore Central optimistic store shared by every hook. State updates are applied synchronously so all hooks on the same key stay in sync immediately, while the actual URL commit is rate-limited and merged across same-tick updates.
NuqsAdapter Bridges the query-params store to TanStack Router. Shallow updates (default) write the URL directly; shallow: false updates navigate through the router so loaders, validation, pending state, and Start SSR participate.
useQueryState useState, but backed by a single URL query key. Route-agnostic: components never import a route object. See useQueryStates for multiple keys.
useQueryStates 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.
useUrlSearchString Reactive read of the full URL query string from the adapter store. Unlike a router hook, this reflects shallow updates (History-API writes that don’t fire router/popstate events). Useful for debugging and live URL readouts.
Name Summary
AdapterValue
CommitFn Adapter callback that writes a rate-limited, merged update to the real URL (e.g. via the router).
CommitInput What the store hands an adapter’s commit: the merged params and the resolved options to write them with.
QueryStateStore Per-adapter URL state store: optimistic updates, subscriptions and rate-limited commits.
ReadValue Read value for a given parser argument; defaults to string | null.
Setter
SetValues
Snapshot Current URL search state held by a QueryStateStore.
StoreUpdate One pending store update: a function over the current params plus the options to commit it with.
TanStackQueryStateAdapterProps
UseQueryStatesOptions
Name Summary
QueryStateAdapterContext The React context every query-state adapter provides (NuqsAdapter, QueryStateTestingAdapter) and that useQueryState / useQueryStates / useUrlSearchString read. Its value is an AdapterValue (the shared store plus adapter defaultOptions), or null outside an adapter, where the hooks throw.