-
Notifications
You must be signed in to change notification settings - Fork 30.3k
docs: add useSearchParams and useParams documentation for Pages Router #88429
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
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
| const router = useRouter() | ||
| const searchParams = useSearchParams() | ||
|
|
||
| const createQueryString = useCallback( |
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.
Don't think we need useCallback here?
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.
It's the same in the existing documentation: https://github.com/vercel/next.js/blob/canary/docs/01-app/03-api-reference/04-functions/use-search-params.mdx#L292
samselikoff
left a comment
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.
Think the useCallback is premature, should we remove it?
|
Yeah it doesn't make sense in that context 👍 |
|
Actually it's the same as the current useSearchParams documentation |

Description
This PR adds dedicated documentation pages for
useSearchParamsanduseParamshooks in the Pages Router documentation.Changes
docs/02-pages/04-api-reference/03-functions/use-search-params.mdxdocs/02-pages/04-api-reference/03-functions/use-params.mdxWhy
Both
useSearchParamsanduseParamsfromnext/navigationwork in the Pages Router, but this was not well documented. The only mention was a brief note in the App Router docs and a migration section in the Pages RouteruseRouterdocs.What's Documented
For both hooks:
nullduring pre-renderinggetServerSideProps(where params are immediately available)For
useParamsspecifically:router.query(which includes both dynamic params and query string params)Related Test
The existing test at
test/e2e/app-dir/params-hooks-compatvalidates that these hooks work in both routers.