Next.js Discord

Discord Forum

How do I extract the id from /[id]/page.tsx using useSearchParams?

Answered
Chum salmon posted this in #help-forum
Open in Discord
Chum salmonOP
I'm trying to create user pages with the folder structure @/app/profile/[id]/page.tsx and am having trouble extracting the id from the page so that I can verify it's the correct user.

Using the Pages folder structure we would use useRouter which would return a query with an id. I know the documentation says useRouter doesn't return a query anymore and to instead use useSearchParams but I'm having trouble finding anything using this
Answered by joulev
you are close, it is actually useParams which is the hook for this https://nextjs.org/docs/app/api-reference/functions/use-params
View full answer

2 Replies