Next.js Discord

Discord Forum

RootLayout confusion

Answered
Whimbrel posted this in #help-forum
Open in Discord
WhimbrelOP
This code prints the Footer component twice.
Can someone explain why?

import {theme} from "../styles/styles.css"                            import {Footer} from './components/interload'                         export default function RootLayout({ children }) {                      return (
    <html lang="en" className="theme">                                    <head>
    <title>title name</title>
    </head>
      <body>
      {children}
      <Footer />
      </body>
    </html>
  )
}
Answered by alfon
You dont need to call rootlayout again here
View full answer

12 Replies

WhimbrelOP
This is the page.js
import {
PopoverDemo,                       MyBio,
Hobby,
Navbar,                            Footer,
} from './components/interload';
import RootLayout from './layout'

export default function Page() {  return (
  <RootLayout>
  <Navbar />
  <PopoverDemo />
  <MyBio />
  <Hobby />
  </RootLayout>
  )
}
@alfon What is the URL you accesed
WhimbrelOP
The home page
This is footer.js
export function Footer(){
return (
<>
<footer>
    <p>&copy; 2023 Your name. All rights reserved.</p>
</footer>
</>
)
}
WhimbrelOP
Unhandled Runtime Error
Error: Hydration failed because the initial UI does not match what was rendered on the server.

Warning: Expected server HTML to contain a matching <footer> in <body>.

See more info here: https://nextjs.org/docs/messages/react-hydration-error

Component Stack
footer
Footer
body
html
This is the error I am getting
Answer
Its already nested for you
WhimbrelOP
Hey thanks @alfon for helping out :blob_aww: