Site Parts in Components in NextJS

In the previous lesson, we wrote the text of the site parts directly in the layout file:

app/layout.jsxexport default function RootLayout({children}) {
  return (
    <html lang="en">
      <body>
        <header>
          header
        </header>
        <main>
          {children}
        </main>
        <footer>
          footer
        </footer>
      </body>
    </html>
  );
}

However, this can be inconvenient when site parts contain a lot of code and text. Therefore, site parts are usually moved into separate component files.

Let's move the site header into a separate component as an example. Let's create the corresponding file:

comp/header/header.jsxexport default function Header() {
  return <>
    header
  </>;
}

Let's import our component into the layout file:

app/layout.jsximport Header from '@/comp/header/header.jsx';

export default function RootLayout({children}) {
  
}

Let's output the text of our component using a tag with its name:

app/layout.jsximport Header from '@/comp/header/header.jsx';

export default function RootLayout({children}) {
  return (
    <html lang="en">
      <body>
        <header>
          <Header />
        </header>
        <main>
          {children}
        </main>
        <footer>
          footer
        </footer>
      </body>
    </html>
  );
}
Задание 1

Create separate components for the site header and footer.