Replies: 6 comments 4 replies
This comment was marked as off-topic.
This comment was marked as off-topic.
-
Coming back to this discussion: I think the behaviour needs to be strongly described as to whether the hook works with a single value or if it returns arrays. Having an either-or case that handles everything, where the output type is |
Beta Was this translation helpful? Give feedback.
-
Would it be possible to have an option on the parseArrayOf parser for checking for this multiple key scenario? I'd expect it to serialize with the comma separated list still, but it would be nice to have an easy way to read in this multiple key scenario for backwards compatibility. Or would middleware be the better place to own this sort of logic somehow? |
Beta Was this translation helpful? Give feedback.
-
Also looking forward to this! It would definitely enhance out-of-the-box support for more readable complex queries such as: |
Beta Was this translation helpful? Give feedback.
-
I would definitely prefer option 2 (i.e. multiple query string params do not get converted to single param with commas). I need to have the querystring set by nuqs match the output of a GET form submit. |
Beta Was this translation helpful? Give feedback.
-
Poll time, what would you think of an API based on The idea would be to keep the same API we currently have for declaring array states, but add some indication to use the native key-duplication rather than a single key and separator for values: // Option A (fewer changes, might be tricky to auto-complete right):
parseAsArrayOf(parseAsString, ';') // key=foo;bar
parseAsArrayOf(parseAsString, { nativeUrlArray: true }) // key=foo&key=bar
// Option B (more userland changes required, but more explicit):
parseAsArrayOf(parseAsString, { repeatKeys: false, separator: ';' }) // key=foo;bar
parseAsArrayOf(parseAsString, { repeatKeys: true }) // key=foo&key=bar Feel free to suggest better names for |
Beta Was this translation helpful? Give feedback.
-
Search params can appear more than once in the query string, like so:
?foo=bar&foo=baz
This reflects in URLSearchParams under a different API:
getAll
to obtain an array of values:['bar', 'baz']
get
would only return the first entry (specification):'bar'
append
does what it says, and adds a new entry when updating (eg:.append('foo', 'qux')
will give?foo=bar&foo=baz&foo=qux
)set
overrides any existing value (eg:.set('foo', 'qux')
will give?foo=qux
)In order to support this, some refactoring of the parsers, hook logic, and type definitions needs to be done, as it only ever worked with one-dimensional values.
Related discussions
Originally posted by @ianldgs in #481 (comment)
Beta Was this translation helpful? Give feedback.
All reactions