Child components of a client component are not client components?
Answered
Peterbald posted this in #help-forum
PeterbaldOP
Hi, this is probably a dumb question but I am currently learning Next and came across a weird issue.
The Next documentation clearly states that 'use client' doesn't need to be defined in every component and that every child component of a client component should be a client component as well.
I tried reproducing that in my own code and it's true, however when I put 'use client' into layout.tsx specifically, only the layout file can use React hooks for example, and the children cannot. They appear to be server components and also need to be marked as such.
Can someone explain this? The example certainly doesn't follow documentation.
The Next documentation clearly states that 'use client' doesn't need to be defined in every component and that every child component of a client component should be a client component as well.
I tried reproducing that in my own code and it's true, however when I put 'use client' into layout.tsx specifically, only the layout file can use React hooks for example, and the children cannot. They appear to be server components and also need to be marked as such.
Can someone explain this? The example certainly doesn't follow documentation.
4 Replies
@Peterbald so the layout gets page.tsx as a child so it's the same as Client components receives a child as a prop and render it.
PeterbaldOP
Ah I get it now, thanks.