Interview kitsBlog

Your dream job? Lets Git IT.
Interactive technical interview preparation platform designed for modern developers.

XGitHub

Platform

  • Categories

Resources

  • Blog
  • About the app
  • FAQ
  • Feedback

Legal

  • Privacy Policy
  • Terms of Service

© 2026 LetsGit.IT. All rights reserved.

LetsGit.IT/Categories/Next.js
Next.jseasy

What does the `'use client'` directive do?

Tags
#use-client#client-component#react
Back to categoryPractice quiz

Answer

It marks a file as a Client Component boundary. The component (and its dependencies) are bundled for the browser, so you can use hooks and event handlers there.

Advanced answer

Deep dive

`'use client'` tells Next.js that this module is a **Client Component boundary**. The file and everything it imports (down the tree) becomes part of the client bundle, and the code executes in the browser.

That enables:

  • React hooks like `useState`, `useEffect`, `useReducer`,
  • event handlers (`onClick`, `onSubmit`),
  • browser-only APIs (`window`, `localStorage`).

Important implications

  • Client Components cannot import server-only modules (DB clients, `fs`, server secrets).
  • A `'use client'` boundary can grow accidentally if you import “too much” into it, increasing JS shipped to users.

Practical guidance

  • Keep `'use client'` components small and focused.
  • Push data fetching up to Server Components and pass serializable props down.
  • Use client-only state only when the UI truly needs it.

Common pitfalls

  • Adding `'use client'` at a layout/root and turning large parts of the app into client-side JS.
  • Importing heavy libraries into a client boundary.
  • Reading `window` during render (do it in `useEffect` if needed).

Related questions

Next.js
Theme toggle hydration mismatch: what causes it and how do you avoid it?
#nextjs#react#hydration
Next.js
What are `useSearchParams()` and `useParams()` used for (and where can you use them)?
#params#search-params#hooks
Next.js
What causes a hydration mismatch in React/Next.js and how do you fix it?
#hydration#ssr
#react
Next.js
Next.js App Router: Server Component vs Client Component — what’s the difference?
#nextjs#app-router#rsc