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 05 / Topic 3 of 6

What a Server Component genuinely cannot do

A Server Component's code runs once on the server and is gone — there is no second render in a browser to attach onClick to, and no browser runtime underneath it to hold useState's value between renders. So neither hooks nor event handlers work there, and this is enforced at build time, not discovered as a confusing runtime bug. Reproduced for real by adding a plain function component that calls useState, with no "use client" anywhere, and importing it into a page:

import { useState } from "react";

export default function MissingDirective() {
  const [count, setCount] = useState(0);
  return <button onClick={() => setCount(count + 1)}>{count}</button>;
}
$ npm run build
...
Error: Turbopack build failed with 1 error:
./app/store/_scratch/no-directive/Comp.tsx:1:10
Error: You're importing a module that depends on `useState` into a React Server Component module. This API is only available in Client Components. To fix, mark the file (or its parent) with the `"use client"` directive.
    Learn more: https://nextjs.org/docs/app/api-reference/directives/use-client

The fix is Part 6's entire subject — add "use client" to the top of that file — not anything this part teaches. The scratch file above was created only to trigger this error and was deleted immediately after; it is not part of the harness's permanent state (the same throwaway-and-delete convention Part 2 used for its _draft folder).

The same restriction covers event handlers, even without a hook in sight — a Server Component cannot pass a function it defined as a prop into a Client Component either, because a function cannot be serialized across the server/client boundary. That specific error, and why it matters for composition rather than for this part's own code, is Part 6's territory (its README reproduces it for real).

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

Search the guide