-
This is how Next.js 15 parses the following URL generated by nuqs:
This is how Next.js 15 parses the following URL:
It could be useful to add this option to avoid manually parsing arrays in the backend |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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. |
Beta Was this translation helpful? Give feedback.
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:
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.