Command Palette

Search for a command to run...

Hectal
Phase 20: Server Components and Next.js
React · Exercise 3 of 5 PreviousNext
Intermediate

Split a page into server and client components

This page runs through a simulated RSC pipeline (at the bottom, don't change it): ProductPage is a server component and AddToCart is a client component. Right now the server passes a click handler to the client component, so the pipeline throws React's real error and the page shows it.

Fix it the RSC way: the server passes only data (productId={product.id}), and AddToCart keeps its own count with useState. Keep the ids: the button is #add and the count text is #count, showing In cart: 0, In cart: 1, …

What Check tests

  1. The pipeline no longer throws (no #error)
  2. The server-rendered heading shows Blue pen
  3. The payload has an AddToCart hole with plain data only
  4. The count starts at In cart: 0
  5. Two clicks on #add show In cart: 2

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.