Return named state and setter #623
Closed
garronej
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
Thanks for sharing! I'll move this to the "Show & Tell", as this isn't really a question/answer kind of discussion. You can (kind of) do that with const [{ foo, bar }, setValues] = useQueryStates({
foo: parseAsInteger,
bar: parseAsStringLiteral(['baz', 'qux'] as const)
})
setValues({ foo: 42 }) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello @franky47,
I don't know if it's a good idea to design an API like that, and you may have already thought of this, but since nuqs require a name to be given for the query parameter,
useQueryState
could potentially return a named setter and getter.Example:
Screen.Recording.2024-09-01.at.22.38.53.mov
But as I said, while it's cool, I stopped using this pattern in my libraries because it was mystifying for people.
It defies their expectations.
Plus, you might potentially want the name of the query parameter to differ from how it's named in your component.
However, I thought it was cool enough to share it with you.
Beta Was this translation helpful? Give feedback.
All reactions