Skip to content

API Reference

Factory function that creates a reactive query string utility.

import { createQsUtils } from "@vp-tw/nanostores-qs";
const qsUtils = createQsUtils(options?);
OptionTypeDescription
qs{ parse, stringify }Custom query string library (default: URLSearchParams)
isEqual(a, b) => booleanCustom equality check (default: es-toolkit isEqual)
PropertyTypeDescription
$searchReadableAtom<string>Current window.location.search string
$urlSearchParamsReadableAtom<URLSearchParams>Parsed URLSearchParams from $search
$qsReadableAtom<Record<string, unknown>>Parsed query object
createSearchParamStore(name, config?) => StoreCreate a single-parameter store
createSearchParamsStore(configs) => StoreCreate a multi-parameter store
destroy() => voidRemove event listeners and unpatch history

Create a reactive store for a single URL query parameter.

import * as presets from "@vp-tw/nanostores-qs/presets";
const store = qsUtils.createSearchParamStore("page", presets.integer({ default: 1, min: 0 }));
ParameterTypeDescription
namestringQuery parameter name
configConfigPreset config or plain config object
Property / MethodTypeDescription
$valueReadableAtom<T>Current decoded value
$resolvedReadableAtom<R>Resolved value (same as $value if no resolve set)
update(value, options?)voidUpdate URL with new value
update.dry(value)stringCompute next search string without side effects

Create a reactive store for multiple URL query parameters.

const store = qsUtils.createSearchParamsStore({
page: presets.integer({ default: 1, min: 0 }),
sort: presets.enum(["newest", "oldest"]),
});

An object mapping parameter names to preset configs.

Property / MethodTypeDescription
$valuesReadableAtom<Record<string, T>>All current decoded values
$resolvedReadableAtom<Record<string, R>>Resolved values (same as $values if no resolve set)
update(key, value, options?)voidUpdate a single parameter
update.dry(key, value)stringDry-run for single parameter
updateAll(values, options?)voidUpdate all parameters atomically
updateAll.dry(values)stringDry-run for all parameters

All update and updateAll calls accept an options object:

OptionTypeDefaultDescription
replacebooleanfalseUse replaceState instead of pushState
keepHashbooleanfalsePreserve current URL hash
stateunknownCustom state for History API
forcebooleanfalseBypass equality check

  • When window is unavailable (SSR), the internal search defaults to an empty string; listeners are not attached.
  • The utility listens to popstate and patches pushState/replaceState to stay reactive.