Can the nested layouts be client components?
Answered
Satin Angora posted this in #help-forum
Satin AngoraOP
I understand that root layout file should be a server component, but what about nested layouts? Can they set to be client components?
19 Replies
instead, create a client component and import it to your layouts
Answer
you can still pass server component to your client component and have SEO and everything with client component that are high up in the tree
Satin AngoraOP
I asked because making my dashboard page server-side is making things too hard, so I was planning to use
Context API to provide required data to it. I think making a wrapper for required context providers is a better idea.Thank you for your answer.
@Satin Angora I asked because making my dashboard page server-side is making things too hard, so I was planning to use `Context` API to provide required data to it. I think making a wrapper for required context providers is a better idea.
https://nextjs.org/blog/security-nextjs-server-components-actions#data-access-layer i recommend following this article if server-side data fetching is hard
Satin AngoraOP
Oh, I do have a repository for database and server. The problem I'm dealing with right now is related to dictionary files. I get a dictionary as JSON file (ie.
en.json) with the language parameter provided from the root layout in server components.The import of the JSON file is async, so I can use
await in server components.But for dashboard, I have auth to handle, so I decided to go full client component. I need a way to pass down the dictionary for the language provided to dashboard and subroutes.
@Satin Angora But for dashboard, I have auth to handle, so I decided to go full client component. I need a way to pass down the dictionary for the language provided to dashboard and subroutes.
just await import JSON file in your dashboard and subroutes
Satin AngoraOP
But I need the language information
export default async function Dashboard({ params }: DashboardProps) {
const dictionary = await getDictionary(params.lang)
...(╯°□°)╯︵ â”»â”â”»
Satin AngoraOP
Yes
Do you happen to have authentication set up @Satin Angora ? I am using the same dictionary method for languages and was wondering how I should build my authentication routes.
Satin AngoraOP
Yes. What exactly do you need help with? I would like to help @Judder
Satin AngoraOP
@Judder When you are up, you can write your issue to a new help post, and @ mention me. I will try to help you.