How do I extract the id from /[id]/page.tsx using useSearchParams?
Answered
Chum salmon posted this in #help-forum
Chum salmonOP
I'm trying to create user pages with the folder structure
Using the Pages folder structure we would use
@/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 thisAnswered 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
2 Replies
@Chum salmon 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
you are close, it is actually useParams which is the hook for this https://nextjs.org/docs/app/api-reference/functions/use-params
Answer
@joulev you are close, it is actually useParams which is the hook for this <https://nextjs.org/docs/app/api-reference/functions/use-params>
Chum salmonOP
Wow thats perfect thank you so much!