LearnThatStack Ace your next interview
Next.js · question
Question 12 of 95

How do you create Client Components in App Router?

beginner
← All Next.js questions
Re-explain

You create a Client Component by adding the 'use client' directive at the top of the file, above the imports. Components in the App Router are Server Components by default, so you opt in only where you need interactivity.

'use client';

import { useState } from 'react';

function Counter() {
  const [count, setCount] = useState(0);
  
  return (
    <button onClick={() => setCount(count + 1)}>
      Count: {count}
    </button>
  );
}

The directive declares a boundary between server and client code. Every module the file imports, and every component it renders directly, joins the client bundle, so you do not repeat the directive in child files. Client Components are still prerendered to HTML on the server, then hydrated in the browser to attach event handlers.

Use one when you need state and event handlers, effects, or browser-only APIs such as localStorage. Keep the directive on small leaf components, such as a button, rather than a whole page, so less JavaScript reaches the browser.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the Next.js cheatsheet.

← Back to all Next.js questions
Pro · $10/mo

81 of 95 Next.js answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime