Skip to content
Learn Netverks

Lesson

Step 14/36 39% through track

use-client-directive

The 'use client' directive

Last reviewed Jun 1, 2026 Content v20260601
Track mode
client_nextjs
Means
In-browser Next.js (client components)
Reading
~2 min
Level
beginner

This lesson

This lesson teaches The 'use client' directive: the concepts, APIs, and habits you need before advancing in Next.js.

Directives extend HTML in 1.x—read link/compile when debugging DOM behavior.

You will apply The 'use client' directive in contexts like: Marketing sites, dashboards, e-commerce, and Vercel-style deployments that need hybrid static + dynamic pages.

Write TSX for Client Components, click Run—React 18 CDN + in-browser TSX compile; use client/server lessons explain App Router concepts; mountApp renders interactive UI; printOutput feeds the terminal.

When you can explain the previous lesson's ideas without copying starter code.

The string 'use client' at the top of a file marks that module and its transitive imports as Client Components. It creates a boundary between server-only code and browser bundles.

Syntax rules

  • Must be the first statement (comments above are fine)
  • Applies to the whole file—you cannot mix server and client in one module
  • Every file in the import chain from a client entry must be client-safe

Common mistake

// BAD: Server Component importing server db into client tree
'use client';
import { getUser } from './server-data'; // pulls server code client-side

// GOOD: Server parent fetches; passes serializable props to client child
// ServerPage.tsx → <ClientProfile user={user} />

Playground behavior

This site’s runner removes 'use client' before execution so the same source matches real Next.js projects while still running in a browser sandbox. Keep writing the directive to build the habit.

Important interview questions and answers

  1. Q: Does 'use client' mean “only render on client”?
    A: It means the module is bundled for the browser and may hydrate—not that SSR is disabled for the whole route.
  2. Q: Can you pass functions from Server to Client Components?
    A: Only through Server Actions or patterns that serialize safely—arbitrary functions are not passed as props.

Self-check

  1. Where must 'use client' appear in a file?
  2. Why should server database code stay out of client files?

Pitfall: Importing server-only modules (db, secrets) into a client file pulls them toward the browser bundle—keep fetches in server parents.

Interview prep

What does 'use client' mean?

The file and its imports are Client Components bundled for the browser—it defines a boundary, not “skip SSR entirely.”

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs in your browser in a sandboxed frame. Backend runners appear when this track’s profile allows them.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Boundary placement?
  • Import server into client?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump