Handling Arrays in Query Parameters with Nuqs Library #517
-
Hello, I'm using the Nuqs library in my Next.js 14.1.0 project and I'm seeking guidance on handling arrays within URL query parameters. Specifically, I'd like to know:
Any examples or documentation references on these points would be greatly appreciated. I couldn't find the necessary information in the documentation, so I'm asking here. I really liked your library!!)) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
If you're talking about multiple keys in the URL giving an array output like URLSearchParam does, this is not currently supported, discussion about API ideas is here: #484 There is however a As for best practices with setting state arrays, it's the same as for a |
Beta Was this translation helpful? Give feedback.
If you're talking about multiple keys in the URL giving an array output like URLSearchParam does, this is not currently supported, discussion about API ideas is here: #484
There is however a
parseAsArrayOf
parser that lets you put an array under a single search param key: https://nuqs.47ng.com/docs/parsers#arraysAs for best practices with setting state arrays, it's the same as for a
useState
: no mutation of the array (so no push/pop), always return a new instance with the added item or filter out the one to remove.