Server Components are the biggest paradigm shift in React since hooks. Understanding the mental model is critical.
The Core Idea
Some components only need to run on the server. They can access databases directly, use server-only APIs, and their code never ships to the client.
Server vs Client Components
| Feature | Server | Client |
|---|---|---|
| Render location | Server only | Both (SSR + client) |
| Bundle impact | Zero JS sent | Adds to bundle |
| State/Effects | No useState/useEffect | Full interactivity |
| Data fetching | Direct DB/API access | Client-side fetch |
| Event handlers | None | onClick, onChange, etc. |
The Boundary Rule
Server Components can import Client Components, but NOT vice versa. Think of it as a one-way door:
The Children Pattern
When to Use Client Components
- Interactive UI (forms, buttons, dropdowns)
- Browser APIs (localStorage, geolocation)
- State management (useState, useReducer)
- Effects (useEffect, event listeners)
- Custom hooks that use state or effects