Menu
Coddy logo textTech

Recap: Server & Client

Part of the Next.js Essentials section of Coddy's React journey — lesson 22 of 47.

challenge icon

Challenge

Medium

Chapter recap: draw the server/client boundary yourself.

The page lists dishes on the server, but it also puts an onClick straight onto a button, so the app won't render at all. Fix it without marking the page as a client component:

  1. In components/OpenHours.jsx, build a client component ('use client' on line 1) that holds an open boolean in state and renders a button with id="toggle". Its text must be Show hours when closed and Hide hours when open.
  2. When open, it also renders a <p> with id="hours" and the text Open 9am-5pm. When closed, that paragraph must not exist.
  3. In app/page.jsx, replace the broken button and the always-visible paragraph with <OpenHours />, imported from '../components/OpenHours'. The heading and the dish list stay exactly as they are: the page remains a server component.

Try it yourself

import './globals.css';

export const metadata = {
    title: 'My App',
};

export default function RootLayout({ children }) {
    return (
        <html lang="en">
            <body>
                {children}
            </body>
        </html>
    );
}

All lessons in Next.js Essentials