Next.js Discord

Discord Forum

Dynamic Segments

Answered
Chausie posted this in #help-forum
Open in Discord
ChausieOP
Hi! I'm using Dynamic Segments with the App router. I have it defined like "/im/[param]".
I display in that page a Navbar that contains a search Input (client component) that should have that param as its default value. The component hierarchy looks like this:
Page (server component, where the param can be accessed) --> Navbar (client component) --> Input (client component).
I tried with the usePathname hook and splitted the path so it returns me the last part (param), but it feels like a bad practice. I also thought about passing the param as a prop to Navbar and then to Input but it also feels like a bad practice, having in mind that I also use that Input in other parts of my app.

How should I approach that?
Answered by American black bear
you can use this, If I understood your question clearly: https://nextjs.org/docs/app/api-reference/functions/use-params
View full answer

6 Replies

ChausieOP
bump
American black bear
you can use this, If I understood your question clearly: https://nextjs.org/docs/app/api-reference/functions/use-params
Answer
American black bear
@Chausie lemme know if it works
ChausieOP
yep! it was exactly that :this_is_fine:
thanks ❤️
American black bear
Congrats, can you mark the message you find helpful as solution?