Course map
Stage 1: App Router Foundations
Stage 2: The Rendering Model
Stage 3: Data, Caching and Mutations
Stage 4: Full-Stack Next.js
Stage 5: Production and Specialization

Part 06 / Topic 3 of 6

What categorically does not cross: event handlers

A function cannot be serialized — there is no JSON-shaped representation of "the code that runs when this button is clicked," because functions close over server-side variables, memory addresses, sometimes server-only modules, none of which exist once the data reaches a browser. This is enforced at build time, reproduced for real against AddToCartCounter itself by adding an onAdded callback prop and passing one in from the Server Component parent:

// AddToCartCounter.tsx — added a prop that doesn't belong here
export function AddToCartCounter({ productId, name, price, onAdded }: { /* ... */ onAdded: () => void }) { /* ... */ }
// QuickAddPage — passing a Server Component's own function down
<AddToCartCounter
  productId={product.id} name={product.name} price={product.price}
  onAdded={() => console.log("added on the server, which is the whole problem")}
/>
$ npm run build
...
Error occurred prerendering page "/store/quick-add/p1". Read more: https://nextjs.org/docs/messages/prerender-error
Error: Event handlers cannot be passed to Client Component props.
  {productId: "p1", name: ..., price: ..., onAdded: function onAdded}
                                                    ^^^^^^^^^^^^^^^^
If you need interactivity, consider converting part of this to a Client Component.

The error's own suggestion is exactly the fix this part already took: AddToCartCounter owns onClick for its own buttons entirely inside its own Client Component file (setQuantity, setAdded), rather than being handed a handler from the server side at all. Both edits above were reverted immediately after capturing this error — the real harness never keeps this broken version.

One category this course doesn't cover yet, on purpose: a Server Action (a function marked "use server") is the one kind of "function" that can cross this exact boundary, because Next.js doesn't serialize it at all — it replaces it with a reference to an endpoint the client calls back into. That's Stage 3's subject (Part 12), not this part's.

Done here? The practice set for Part 6 — including the solutions — is on the part page.

Search the guide