-
-
Notifications
You must be signed in to change notification settings - Fork 100
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
withDefaults
should (optionally) populate the URL
#405
Comments
I don't think it's a good idea, and I don't think this is a bug. This feature is working as it's intended to be.
Not sure about SEO, I don't think the params in URL are designed for readability.
If the state has default value, then the user doesn't even need to care if the state exists on param or not. The existence of a default value represents the default state expected by the programme designer
Because they have changed the default state of the application.
Such behavior is divisive, this goes against your previous thoughts. |
I agree in not calling this a bug, but it's not really a feature either. There is definitely something missing in the way things are implemented at the moment, and that is distinguishing a missing search param from an invalid one. At the moment, parsers only have one option: return null when they can't correctly turn a query string value into the underlying JS type. But null is also used to indicate that the query key is missing altogether. The default value was slapped onto the problem to help with type safety, ie to ensure there never was a nullish ( But this is clearly causing confusion and not allowing a proper distinction between two very different cases. This will be made even more apparent when introducing validation in parsers (eg with Zod). |
In my understanding it has always been a feature for type safety and null value safety. Do we need to make a distinction between them or just simply rename it as |
Its less about invalid params for me, but about how to handle the initial state. With From a meta level of view, I notices that I still have to re-align my mental model of the library as "useState-first and URL second". (Which is also why I just created #408 to talk about clarifying this.) From a feature point of view, it would be great to have the option to use Also, feel free to move this ticket into the Ideas section. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
(Extracted from #404 (comment))
Right now,
withDefaults
does set the internal state but it does not populate the URL.The URL is only first populated once an explicit
setConfig
(foruseQueryState('config')
) is called.There are minor issues with this approach:
useQueryState
is also the order in which the URL params are sorted, which is great for SEO and readability of the URLFor my usecase, it would be perfect if setting the URL where an option on
withDefaults
. With this I could decide per param if I want this to be visible in the URL right away or not. I have params that would ideally be visible right away and some that should only show once a user interacts with a less used feature.The text was updated successfully, but these errors were encountered: