|
(Extracted from #404 (comment)) Right now, There are minor issues with this approach:
For my usecase, it would be perfect if setting the URL where an option on |
Replies: 4 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. |
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 (
null | undefined) value …