[question/bug] Should parsers be called per hook? #1223
Replies: 2 comments
-
|
.. I found the answer to my own question, but if anyone else ends up here, this caveat is documented with a proposed solution: https://nuqs.dev/docs/troubleshooting#different-parsers-on-the-same-key |
Beta Was this translation helpful? Give feedback.
0 replies
-
You can re-serialise it from a "hydrated" (parsed) value using the serializer API: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm new to nuqs, so I'm unsure if this is intended or not.
I have a param like
name={operator}.{value}. Example:/some-page?name=eq.ericIn my Next.js application, I parse it as a string on the server because that's the format I need the param in there. On this page, I have two client side components, Component A and B.Component A
In Component A, I need to parse the value with a custom parser. The end goal is to destructure the information into an object, like this:
{ operators: ['eq'], value: 'eric' }. So I grab the value like this:Component B
In Component B, I need the value as a string to pass along to another API call. So, I grab the value like this:
The problem
On the first render, this works as I would expect. Component A has the object state, and Component B reads the state as a string. However, if I update the state from either of the components, the parser doesn't seem to be called. Whatever I update the state to (an object or a string) is what I get back from both hook calls.
I'm humble to the fact that I might be thinking about this the wrong way, but I can't seem to find a better solution than not using custom parsers for this use case.
Any ideas and thoughts are welcome. Here's a reproduction:
https://codesandbox.io/p/devbox/nuqs-question-or-bug-report-forked-8xrfjp
Beta Was this translation helpful? Give feedback.
All reactions