The use client boundary
What "use client" actually declares, why it marks a boundary in the module graph rather than one component, and how to keep client JavaScript small.
The use client boundary
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- `"use client"` at the top of a file declares a boundary between the server and client module graphs; the file, everything it imports, and the components it renders directly are in the client bundle.
- You do not add the directive to every client component, only to the entry file where the boundary starts, so a handful of directives usually cover a whole interactive section.
- Mark the smallest interactive piece as a Client Component, such as a search box or a like button, and leave the surrounding layout on the server to keep the JavaScript bundle small.
- A Client Component still renders once on the server for the initial HTML; "client" means it also runs in the browser, not that it only runs there.
Why a directive exists
Server Components are the default, but a page without any interactivity is a brochure. You need a way to say “this part runs in the browser.” Next.js and React use a directive at the top of a file:
// components/like-button.tsx
"use client";
import { useState } from "react";
export function LikeButton({ initial }: { initial: number }) {
const [likes, setLikes] = useState(initial);
return <button onClick={() => setLikes(likes + 1)}>{likes} likes</button>;
}
Without "use client" the build rejects useState in this file. With it, the component can hold state, handle events, use effects and read browser APIs.
It marks a boundary, not a component
This is the idea people miss. "use client" does not decorate one component. It declares a boundary between two module graphs. Think of two trees of imports: the server tree starts at your layouts and pages, and the client tree starts wherever a file declares "use client".
Everything the marked file imports joins the client tree, along with the components it renders directly. So you do not repeat the directive in every file below. Put it on LikeButton, and if LikeButton imports an Icon, Icon is client code too, with no directive of its own.
The boundary is also why the directive belongs at the entry point of an interactive section, not scattered about. A handful of "use client" files usually cover an entire interactive area.
Keep the boundary small
Everything on the client side of the boundary ships to every visitor. So push the boundary down to the smallest piece that needs it.
Suppose a layout has a logo, nav links, and a search bar. Only the search bar needs state. Marking the whole layout as a Client Component would send the logo and nav code to the browser for no reason. Mark the search bar and leave the rest on the server:
// app/layout.tsx (Server Component)
import { Search } from "@/components/search"; // has "use client"
export default function RootLayout({ children }: LayoutProps<"/">) {
return (
<html lang="en">
<body>
<nav>
<a href="/">Home</a>
<Search />
</nav>
{children}
</body>
</html>
);
}
A useful test: if a component does not use state, effects, event handlers or browser APIs, it does not need the directive. Chances are it can stay on the server. If a big component needs only one stateful bit, split the bit out.
“Client” does not mean “browser only”
The name misleads. In Next.js a Client Component is rendered on the server once to produce the initial HTML, and then hydrated in the browser. A console.log in one shows up in your terminal and in the browser console on a direct visit. On a later client-side navigation it renders in the browser alone. So the useful mental table is:
| Runs on the server | Runs in the browser | |
|---|---|---|
| Server Component | yes | no |
| Client Component | yes (initial HTML) | yes |
This matters for browser APIs: reading window in the body of a Client Component fails during the server render. Read it in an effect or event handler, which only run in the browser.
Passing data across
Props from a Server Component to a Client Component must be serializable, since they cross the network inside the RSC payload: strings, numbers, booleans, plain objects and arrays, dates, promises, and Server Functions. Functions you define yourself and class instances will not work. The React-level rules are in the React roadmap’s server components vs client components. I verified the LikeButton example above compiles and builds under Next.js 16.
What the video covers
ByteGrad’s chapters are titled “Blunder #1” through the discussion of client versus server components, when to refactor, “Blunder #2,” the boundary, and importing twice. The video is a practical guide to where "use client" belongs and the mistakes of overusing it, which suits this lesson. It was published in 2023, so a couple of details predate Next.js 15 and 16. The directive’s rules have not changed.
Where this fits
You know how to opt a piece in and why to keep it small. Next, composing server and client components covers nesting the two kinds inside each other.
Check yourself
If `Counter.tsx` has `"use client"` and imports `Button.tsx` without the directive, where does `Button` run?
In the browser as well. Once a file is marked, everything it imports and renders directly is part of the client bundle. You do not need the directive on `Button`; the boundary starts at `Counter`.
Why is putting `"use client"` at the top of a root layout usually a mistake?
It makes the layout and everything it imports ship to the browser, which defeats the point of Server Components. Mark only the small interactive leaves and keep the layout on the server.
Does a Client Component run only in the browser?
No. It is also rendered once on the server to produce the initial HTML, then hydrated in the browser. On later client-side navigations it renders in the browser alone.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.