Next.js Discord

Discord Forum

Client-Component Wraps Server-Component

Answered
sudo posted this in #help-forum
Open in Discord
Hello,
NextJS 14 App Router.
If in the layout.tsx file,

export default function RootLayout({ children, }: { children: React.ReactNode }) { return ( <html lang="en"> <body className={inter.className}> <NotiProvider> <Navbar></Navbar> {children} </NotiProvider> </body> </html> ) }
I have this layout.

If NotiProvider is defined in src/app/context/NotiContext.tsx which is marked with use client.
This means that all pages inherting this layout, and all the components in these pages, will be client-components?
Will i lose the NextJS Server-side rendering aspect for these pages/components?

9 Replies

If you have
export default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    <html lang="en">
      <body className={inter.className}>
          <Provider> // clientside
                {children} // server component
        </Provider>
      </body>
    </html>
  )
}

yes
Answer
Much appreciated! Thanks @B33fb0n3
on it