Server Components vs Client Components ("use client" boundary)
Server Components vs Client Components ("use client" boundary)
Understanding when to use React Server Components (RSC) and when to introduce the "use client" boundary is the single most important conceptual skill in modern Next.js engineering.
1. Comparing Server vs Client Components
| Feature | Server Components (Default) | Client Components ("use client") |
|---|---|---|
| Execution Environment | Runs only on the server | Pre-rendered on server, hydrated in browser |
| Browser Bundle Impact | 0 KB (Dependencies stay on server) | Added to browser JavaScript bundle |
| Direct Backend Access | Full access to databases, filesystems, env secrets | No direct access to databases/secrets |
| React Hooks | ❌ No useState, useEffect, useReducer | ✅ Full access to state, lifecycle, and custom hooks |
| Browser APIs & Events | ❌ No onClick, onChange, window, localStorage | ✅ Full access to DOM events and browser APIs |
2. The "use client" Boundary
Adding "use client" at the very top of a file declares a boundary between server-only code and code that needs client interactivity. It does NOT mean the component runs only on the client! It will still be pre-rendered to HTML on the server during initial load, then hydrated in the browser with event listeners.
3. Composing Server and Client Components (The Golden Rule)
"Push client components down to the leaves of your component tree."
Instead of marking your entire page with 'use client', keep your layout and pages as Server Components (fetching data and securing secrets), and only import small client components where interactivity is strictly required:
Multiple Choice Questions
'use client' directive at the top of a file do?children prop into a Client Component?Data Fetching in Server Components & Async Server Logic
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Related Lessons
Practice Quiz
Test your understanding of this lesson with 5 questions. Each question has one correct answer.