Next.js Discord

Discord Forum

if i made the layout.tsx that warps the entire app "use client" to use react hooks

Answered
Himalayan posted this in #help-forum
Open in Discord
HimalayanOP
if i made the layout.tsx that warps the entire app "use client" to use react hooks, will it affect the entire app? cuz i need to get the pathname, i dont want to show the navbar and the footer in "/login" or "sign-up" even if the "layout.tsx" that has these components warps them
Answered by Rafael Almeida
yeah adding 'use client' is pretty bad in the layout file. its better to use route groups for what you are trying to do: https://nextjs.org/docs/app/building-your-application/routing/route-groups
View full answer

11 Replies

HimalayanOP
i'm using headers but the problem with that is the value not being updated, so i need to use hooks ig
is there any better solutions?
yeah adding 'use client' is pretty bad in the layout file. its better to use route groups for what you are trying to do: https://nextjs.org/docs/app/building-your-application/routing/route-groups
Answer
@Youssef Why don't you just create multiple layouts ?
HimalayanOP
cant in this case
it will be the same
no, the layouts are composed on top of each other. what you need to do is to create multiple root layouts: https://nextjs.org/docs/app/building-your-application/routing/route-groups#creating-multiple-root-layouts
so you would have a group for /loginand /sign-up with a layout without the navbar and footer and the rest of the pages go in the other group
HimalayanOP
got it
ty!