parseAsArrayOf
function parseAsArrayOf<T>(itemParser, separator?): Parser<T[]>;Defined in: tanstack/core/built-in-parsers.ts:305
Array packed into a single key, comma-separated by default (?ids=1,2,3).
Each item goes through itemParser; items that fail to parse are dropped
("1,x,3" → [1, 3], "x" → []), and an empty value is []. It never
returns null, so clearOnInvalid never strips the key (same as nuqs).
A separator inside an item is percent-encoded so it round-trips.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type | Default value |
|---|---|---|
itemParser |
AnySingleParser<T> |
undefined |
separator? |
string |
"," |
Returns
Section titled “Returns”Parser<T[]>
Example
Section titled “Example”import { parseAsArrayOf, parseAsInteger, parseAsString } from "@xtandard/lib/tanstack";
const ids = parseAsArrayOf(parseAsInteger);ids.parse("1,2,3"); // → [1, 2, 3]ids.serialize([1, 2, 3]); // → "1,2,3"
parseAsArrayOf(parseAsString, "|").serialize(["a", "b"]); // → "a|b"