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
childrenprops 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> ); } 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) 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)