Skip to content
Tutorials Center
My learning

Topics

React Reference ยท Top-Level React APIs

The "use client" directive

Reference for the "use client" directive: how it marks the boundary between server and client code, what it makes bundled, and what props may cross it.

"use client" is a directive placed at the very top of a file. In an app with Server Components, every component is a Server Component by default: it renders on the server and ships no JavaScript. Adding "use client" declares that this file, and everything it imports, belongs to the client bundle, where state, effects and event handlers work.

You put the directive on the entry points of interactive islands, not on every file. Children imported by that file are already on the client side of the boundary and need no directive of their own.

JSX
'use client';

import { useState } from 'react';

export default function LikeButton() {
  const [likes, setLikes] = useState(0);
  return <button onClick={() => setLikes(likes + 1)}>Likes: {likes}</button>;
}

Try it

The live editor is a plain client-only React page, so every component here already behaves like a Client Component. The directive is accepted and ignored.

A client component
Server shell, client island

Syntax

JSX
'use client';   // first statement in the file, before any import

import { useState } from 'react';
Rule Detail
Position The first statement of the module. Only comments may precede it.
Scope The whole file and all modules it imports (transitively) join the client bundle.
Exports Components become client references. A Server Component can render them but not call them as functions.
Props across the boundary Must be serializable: primitives, plain objects and arrays, Date, Map, Set, promises, JSX elements, Server Function references. Plain functions are not allowed.
children JSX passed as children or other props from a Server Component stays a Server Component output, so you can nest server content inside a client shell.

Usage notes

  • The directive marks a boundary in the import graph, not a component type. A client file can import other files freely; those are bundled for the browser.
  • Needed when a component uses state, effects, refs to DOM nodes, browser APIs, or event handlers such as onClick. Do not add it just to be safe: it grows the bundle.
  • Put it as low in the tree as practical: a small LikeButton island rather than the whole page.
  • Client Components still render on the server first (HTML for the first paint) in frameworks with server rendering, then hydrate in the browser. "Client" means "also runs in the browser", not "never on the server".
  • Passing an inline function from a Server Component to a client prop fails because it cannot be serialized. Move the handler into the client file, or pass a Server Function.
  • A Client Component cannot import a Server Component module. Pass it as children instead.
  • Context providers must be Client Components, so wrap them in a small 'use client' file and render inside.
  • This is not "use server". That directive exposes server functions; this one moves code to the client.