BitlystBitlyst
PostsSeriesTopicsAbout

Bitlyst

Short, diagram-first posts on JavaScript, React & Next.js. Follow via RSS or the newsletter.

© 2026 Mohsen Fallahnejad

PostsSeriesTopicsLinksAboutRSSGitHubX
Posts/nextjs
Beginner2 min read

What is 'use client' in Next.js?

Understand 'use client' in Next.js App Router: what it means, when to use it, and how it works under the hood.

Mohsen Fallahnejad

Mohsen Fallahnejad

Sep 23, 2025Discuss

Next.js App Router defaults all components to Server Components.
The "use client" directive marks a file as a Client Component.

use clientuse client


1) What does it do?#

  • Placed at the top of a file: "use client";
  • Tells Next.js: render this component on the client (browser).
  • Without it → the file stays a Server Component.
tsx
// Button.tsx
"use client";

export default function Button() {
  return <button onClick={() => alert("Clicked!")}>Click me</button>
}

Without "use client", this would break: event handlers & useState only work in the browser.


2) Why is it needed?#

  • Next.js defaults to Server Components for speed & smaller bundles.
  • "use client" is an escape hatch when you need client-only features.

3) When to use it?#

You need "use client" if you use:

  • React hooks: useState, useEffect, useRef
  • Event handlers: onClick, onChange, …
  • Browser APIs: localStorage, window, document
  • Client-only libraries: Chart.js, React-Quill, etc.

4) How does it work internally?#

  • Next.js scans for "use client" at build time.
  • That file + its imports → shipped as JS bundle to the browser.
  • Server Components are stripped to HTML + serialized props.

5) Mixing Server & Client Components#

  • Server Components can import Client Components.
  • Client Components cannot import Server Components.
tsx
// page.tsx (Server Component)
import Button from "./Button";

export default function Page() {
  return (
    <div>
      <h1>Hello</h1>
      <Button />  // Client-side, interactive
    </div>
  );
}

6) Mental Model 🧠#

  • Default = Server Component (fast, no client JS).
  • Add "use client" only where you need state, events, or browser APIs.
  • Sprinkle sparingly → keep most of your tree on the server.

⚡ "use client" is the switch that brings React interactivity into your Next.js App Router components.

Filed under#nextjs#react#use-client#server-components#frontend

Was this worth your time?

One tap tells me what to write more of.

Mohsen Fallahnejad

Written by

Mohsen Fallahnejad

Frontend engineer explaining JavaScript, React & Next.js internals in posts you can finish over coffee. More about me

X ↗GitHub ↗LinkedIn ↗
← OlderNext.js Page Router vs App RouterNewer →JavaScript is Single-Threaded

Start the discussion

Questions, corrections, a better approach? I read and reply to every comment.

Read next

Next.js Page Router vs App Router

Understand the key differences between the old Page Router and the new App Router in Next.js.

Sep 23, 20252 min read

MVVM, Micro‑Frontends, and Domain‑Driven Frontend — A Practical Guide

Clear, practical explanations of MVVM, micro‑frontends, and domain‑driven design for modern React/Next.js teams, with examples, folder structures, and trade‑offs.

Sep 15, 20256 min read

The Server Action That Ran Twice, but Only on localhost

Why a Next.js Server Action called from useEffect runs twice in development: React Strict Mode mounts every component twice. What that reveals, and where the call belongs.

Nov 3, 20264 min read

Get new posts in your inbox

No spam. Unsubscribe any time.

2 min left
Discuss👍 React
👍