Skip to content

Option to repeat params for arrays instead of using commas #820

Answered by franky47
lpbonomi asked this question in Ideas
Discussion options

You must be logged in to vote

This is the topic of #484, and I agree it would be nice to support this standard.

For an immediate way of parsing them on the server, you can do the following:

import { parseAsArrayOf, parseAsInteger } from 'nuqs/server'

// Note: you can share this definition with useQueryState(s) on the client, the serializer helper etc..
const templateIdParser = parseAsArrayOf(parseAsInteger).withDefault([])

const templateIds = templateIdParser.parseServerSide('6,2')
//    ^? [6, 2]

Note that a more scalable way of "loading" search params from an object describing keys and associated parsers (as we use in many parts of the nuqs API) is coming in nuqs 2.3.0 in the form of loaders, see #818.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by lpbonomi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants