-
-
Notifications
You must be signed in to change notification settings - Fork 135
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
Add default values #197
Comments
It's possible to use function overloads to detect the use of a default value in the options, and update the return type accordingly. Regarding two hooks with the same key having different default values, this fall out of the scope of this library. If someone wants to prevent such errors from happening, wrapping The URL will not be updated by the use of a default value if the query is missing. It's still possible to do |
@franky47 Is there a reason as to why this hasn't been merged & released? |
Yes: I don't have time to work on this currently. |
Ah, I thought your commit for this issue finished it. |
I think there are some caveats that may need attention before providing such a solution, as mentioned in the comments up there, like how to deal with URL/state discrepancies when using default values. If you have some feedback on that matter, I'd love to hear it! |
Note: this was released in 1.4.0. As for the behaviour with default values:
TL;DR: the default value only exists in the React tree as a fallback for when the query key is not present in the URL. |
For when the query is not present, instead of returning
null
.This should be done in a non-breaking way, as there are multiple use-cases for useQueryState:
Having a default value in React does not automatically update the URL to reflect it, which is debatable. If updating the URL, it would cause a side-effect depending on when the hook's parent component is mounted. If not, it breaks the idea that the URL is the source of truth (what if two hooks have different default values ?).
Use-cases in client code:
The text was updated successfully, but these errors were encountered: