Skip to content

Can App Layout be used in NextJs layout file? #1809

Answered by Al-Dani
rexwreyes asked this question in Q&A
Discussion options

You must be logged in to vote

Posting here for posterity, as it was discussed in more details in a separate request.

App Layout cannot be used in the server part of the layout file, because it uses hooks that wouldn't work on a server.
You would have to create a client-side wrapper where you can pass children to the content slot:

// client-layout.tsx
"use client";
import { AppLayout } from "@cloudscape-design/components";

export default function ClientLayout(props: { children: React.ReactNode }) {
  return <AppLayout content={props.children} />;
}

and use it in the layout:

// layout.tsx
...
import ClientLayout from './client-layout';
..
export default function RootLayout({ children }: { children: React.ReactNode }) …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Al-Dani
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants