Utilities
Utilities for working with query strings
Serializer helper
To populate <Link>
components with state values, you can use the createSerializer
helper.
Pass it an object describing your search params, and it will give you a function to call with values, that generates a query string serialized as the hooks would do.
Example:
Base parameter
The returned serialize
function can take a base parameter over which to
append/amend the search params:
Shorter search params keys
Just like useQueryStates
, you can
specify a urlKeys
object to map the variable names defined by the parsers
to shorter keys in the URL:
Parser type inference
To access the underlying type returned by a parser, you can use the
inferParserType
type helper:
For an object describing parsers (that you’d pass to createSearchParamsCache
or to useQueryStates
), inferParserType
will
return the type of the object with the parsers replaced by their inferred types: