0

The 'use client' boundary

Modelused in ~100% of apps

This is the one idea interviewers use to tell a real Next.js developer from a tutorial-follower: when does a file run on the server, and when does it run in the browser? Get the boundary wrong and you either leak secrets to the client or ship a megabyte of needless JavaScript.

Core idea. Everything in the App Router starts on the server by default. `"use client"` is not 'run this in the browser' — it's a network boundary marker that says 'from here down, also send this code to the browser and hydrate it.' You put it at the leaves that need interactivity, not at the top.
Playground, this isn't a screenshot
component tree server client
<LikeButton />Server Component
Build error: useState / onClick are not allowed in a Server Component. Add "use client" to fix it.
Render HTML / read props
await data directly (db, fetch)
useState / useEffectclient only
onClick & event handlersclient only
window / localStorageclient only
JS shipped to browser0 KB
JavaScript shipped to the browser0 KB / 71 KB if all client

2 interactive component(s) are still Server Components— they would crash the build because Server Components can't use state or event handlers. Select one and add "use client".

↑ play a little first, then dig in