-
-
Notifications
You must be signed in to change notification settings - Fork 798
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
[legacy-framework] Add useParams
and useRouterQuery
hooks
#574
[legacy-framework] Add useParams
and useRouterQuery
hooks
#574
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah nice, very clever!
I think useRouterParams
can simply rely on router.query
and remove any keys found in useRouterQuery
unless the value is different.
So for route /[id]
with pathname /1?id=2&name=fox
:
router.query | useRouterParams | useRouterQuery |
---|---|---|
id = 1 | id = 1 | id = 2 |
name = fox | name = fox |
Can you also add some tests for this?
Lastly, before merging this we should resolve our discussion in #530 about number parsing. Maybe we can have useParamsStr
, useParamsInt
, and useRouterQuery
@anteprimorac can you also add at least one unit test for |
@anteprimorac Also rerun prettier with our config, it seems like some files weren't formatted correctly |
I've changed store example to use It's hard to write unit tests because it depends on
🤔 it looks like there is a separate prettier configuration for each example. Going to fix it now. Thanks for pointing this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, great! Few more minor things :)
README.md
Outdated
@@ -270,6 +270,7 @@ Thanks to these wonderful people ([emoji key](https://allcontributors.org/docs/e | |||
|
|||
<!-- markdownlint-enable --> | |||
<!-- prettier-ignore-end --> | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@merelinguist this change was introduced by husky pre-commit hook
@flybayer if you agree, we can merge this as it is and gather more info on what to provide regarding validation, sanitization and casting of params and queries. |
@anteprimorac let's wait until we resolve our discussion in blitz-js/legacy-framework#433. I just made another comment. And if we add |
@anteprimorac what do you think about also changing Current: // Everything lumped in query
const {query} = useRouter() Idea: // Separate route params from query string items
const {params, query} = useRouter() This would be a breaking change for existing blitz apps |
@flybayer that’s an excellent idea. We could provide |
Yes exactly. I think we should do that |
useRouterParams
and useRouterQuery
hooksuseParams
and useRouterQuery
hooks
useParams
and useRouterQuery
hooksuseParams
and useRouterQuery
hooks
Related: blitz-js/legacy-framework#433
What are the changes and their implications?
This PR implements two hooks
useRouterParams
anduseRouterQuery
.Checklist
Breaking change: yes/no
No.
Other information
Example of usage: