Tutorial C · builder
Server vs Client Components
Build a small page, decide where 'use client' goes, and watch components cross into the browser on the map.
The page shows product info, a static article and an add-to-cart button. The button calls a Server Action and shows a pending state with useActionState, so it needs the browser. Make it work without turning the whole page into client code. (A plain <form action={serverAction}> with no pending UI would need no client component JavaScript at all; the framework runtime still loads.)
Goal: No errors, add-to-cart present, and at most 6 kB of component JavaScript.
Not there yet
- 1 error to fix first.
- Client estimate 0 kB is within the 6 kB budget.
02Place the boundary
Select a node, toggle 'use client', and decide how children are attached.
Pageserver2 kB
Add to cart buttonserver3 kB
03Add a component
Drag onto a node in the tree, or press + to place under Page.
Product info
Reads the product row from the database and renders name, description and stock.
server data · 4 kB
Interactive filters
Checkbox and range filters held in React state; updates the URL on change.
state · handlers · 14 kB
Search input
A controlled text input with debounced onChange.
state · handlers · 6 kB
3D viewer
React Three Fiber canvas. Needs WebGL and window; ships Three.js.
handlers · browser API · 180 kB
Static article
Markdown rendered to HTML. No interactivity, no data access.
3 kB
Product list
Queries products on the server and renders a list. Can wrap other components.
server data · 5 kB
Add to cart button
Calls a Server Action from onClick and shows a pending state with useActionState.
state · handlers · 3 kB
Analytics beacon
useEffect that reports a page view with navigator.sendBeacon.
browser API · 2 kB
Price badge
Formats a number as currency. Pure; works anywhere.
1 kB