DEV Community

David J Song
David J Song

Posted on

Understanding "use client" in Next.js: What It Really Affects

Many developers misunderstand how "use client" works in Next.js App Router (React Server Components).

It doesn’t make everything below it client-rendered. It only changes the behavior of the file itself and what it directly imports.

1. The Common Misconception

You might have heard:

“If you use "use client", all your child components become client components.”

That’s false.


2. The Real Rule

When you add "use client" at the top of a file:

  • ✅ That file becomes a client component.
  • ✅ Anything it imports becomes a client component too.
  • 🚫 But components passed in as children props are not affected.

Children remain whatever they were defined as (server or client).


3. Example: Safe Provider Pattern

// app/providers.tsx
"use client";

import { ThemeProvider } from "@mui/material";
import { QueryClientProvider } from "@tanstack/react-query";

export function Providers({ children }: { children: React.ReactNode }) {
  return (
    <ThemeProvider>
      <QueryClientProvider>{children}</QueryClientProvider>
    </ThemeProvider>
  );
}
Enter fullscreen mode Exit fullscreen mode

This Providers component is a client component, because it needs React context, hooks, and browser logic.

But {children} are not converted to client components — they stay server-rendered.


4. How It Works

When a server component (like your layout) calls a client component:

layout.tsx (server)
 └── Providers.tsx ("use client")
       └── children (server or client)
Enter fullscreen mode Exit fullscreen mode

React Server Components serialize the child tree as HTML and pass it into the client boundary.

The Providers component doesn’t recompile or import the children — it just receives them as already-rendered markup.


5. Why This Matters

Keeping most of your UI as server components gives you:

  • Smaller JS bundles
  • Faster page load
  • Better SEO and streaming performance

Use "use client" only when you need:

  • Hooks like useState, useEffect
  • Event handlers (onClick, onChange)
  • Access to window or browser APIs

So now I am no more "use client"-phobic. 😂

Top comments (0)