Next.js Server Components
Expert guidance for using Next.js Server Components effectively.
Quick Reference
| Concept |
Pattern |
When to Use |
| Server Component |
Default (no "use client") |
Data fetching, heavy computation, no interactivity |
| Client Component |
Add "use client" |
State, hooks, browser APIs, event handlers |
| Layout |
app/layout.tsx |
Shared UI across routes |
| Template |
app/template.tsx |
Shared UI that re-renders on navigation |
| Server Action |
async function in Server Component |
Form mutations, data updates |
| Parallel Routes |
folder@(sidebar) |
Independent route segments |
What Do You Need?
- Server vs Client - Choosing the right component type
- Data fetching - Async components, caching, revalidation
- Server Actions - Form handling, mutations
- Patterns - Composition, prop drilling prevention
- Streaming - Suspense boundaries, loading states
Specify a number or describe your Next.js component scenario.
Routing
| Response |
Reference to Read |
| 1, "server", "client", "boundary" |
component-types.md |
| 2, "data", "fetch", "cache", "revalidate" |
data-fetching.md |
| 3, "action", "mutation", "form" |
server-actions.md |
| 4, "pattern", "composition", "prop drilling" |
patterns.md |
| 5, "suspense", "loading", "streaming" |
streaming.md |
Essential Principles
Default to Server Components: Only add "use client" when you genuinely need client-side features. This is the single most important Next.js best practice.
Server Components for: Data fetching, database queries, API calls, heavy computation, keeping sensitive tokens safe.
Client Components for: State (useState), effects (useEffect), browser APIs, event handlers, React hooks.
Push Client Components down: Move "use client" as deep in the tree as possible. Keep the root Server Component.
Common Issues
| Issue |
Severity |
Fix |
| Client Component that should be Server |
High |
Remove "use client", make async |
| Fetching in useEffect |
High |
Use Server Component or Server Action |
| "use client" at root |
Medium |
Push down to leaf components |
| Not using async for data fetching |
Low |
Make Server Component async |
| Prop drilling through Server |
Low |
Pass to Client child, don't bridge |
Code Patterns
Server Component (Default)
// Good: Async Server Component
export default async function UserProfile({ userId }: { userId: string }) {
const user = await fetchUser(userId)
return <div>{user.name}</div>
}
Client Component (When Needed)
"use client"
import { useState } from 'react'
export function InteractiveButton() {
const [count, setCount] = useState(0)
return <button => setCount(c => c + 1)}>{count}</button>
}
Server Action
// Server Action in Server Component
async function createTodo(formData: FormData) {
'use server'
const title = formData.get('title') as string
await db.todos.create({ title })
}
export default function Page() {
return <form action={createTodo}>...</form>
}
Reference Index
Success Criteria
Components are correct when:
- Default to Server (no "use client" unless needed)
- "use client" only for interactivity, browser APIs, hooks
- Data fetching in Server Components, not useEffect
- Server Actions for mutations, not API routes
- Client boundaries pushed down as far as possible
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: nextjs-server-components-23description: Next.js App Router Server Components, Client Components, layouts, data fetching, and Server Actions. Use when working with Next.js app directory, component boundaries, or data fetching patterns. Use when this capability is needed.4---56# Next.js Server Components78Expert guidance for using Next.js Server Components effectively.910## Quick Reference1112| Concept | Pattern | When to Use |13|---------|---------|-------------|14| Server Component | Default (no "use client") | Data fetching, heavy computation, no interactivity |15| Client Component | Add "use client" | State, hooks, browser APIs, event handlers |16| Layout | app/layout.tsx | Shared UI across routes |17| Template | app/template.tsx | Shared UI that re-renders on navigation |18| Server Action | async function in Server Component | Form mutations, data updates |19| Parallel Routes | folder@(sidebar) | Independent route segments |2021## What Do You Need?22231. **Server vs Client** - Choosing the right component type242. **Data fetching** - Async components, caching, revalidation253. **Server Actions** - Form handling, mutations264. **Patterns** - Composition, prop drilling prevention275. **Streaming** - Suspense boundaries, loading states2829Specify a number or describe your Next.js component scenario.3031## Routing3233| Response | Reference to Read |34|----------|-------------------|35| 1, "server", "client", "boundary" | [component-types.md](./references/component-types.md) |36| 2, "data", "fetch", "cache", "revalidate" | [data-fetching.md](./references/data-fetching.md) |37| 3, "action", "mutation", "form" | [server-actions.md](./references/server-actions.md) |38| 4, "pattern", "composition", "prop drilling" | [patterns.md](./references/patterns.md) |39| 5, "suspense", "loading", "streaming" | [streaming.md](./references/streaming.md) |4041## Essential Principles4243**Default to Server Components**: Only add "use client" when you genuinely need client-side features. This is the single most important Next.js best practice.4445**Server Components for**: Data fetching, database queries, API calls, heavy computation, keeping sensitive tokens safe.4647**Client Components for**: State (useState), effects (useEffect), browser APIs, event handlers, React hooks.4849**Push Client Components down**: Move "use client" as deep in the tree as possible. Keep the root Server Component.5051## Common Issues5253| Issue | Severity | Fix |54|-------|----------|-----|55| Client Component that should be Server | High | Remove "use client", make async |56| Fetching in useEffect | High | Use Server Component or Server Action |57| "use client" at root | Medium | Push down to leaf components |58| Not using async for data fetching | Low | Make Server Component async |59| Prop drilling through Server | Low | Pass to Client child, don't bridge |6061## Code Patterns6263### Server Component (Default)64```typescript65// Good: Async Server Component66export default async function UserProfile({ userId }: { userId: string }) {67 const user = await fetchUser(userId)68 return <div>{user.name}</div>69}70```7172### Client Component (When Needed)73```typescript74"use client"7576import { useState } from 'react'7778export function InteractiveButton() {79 const [count, setCount] = useState(0)80 return <button onClick={() => setCount(c => c + 1)}>{count}</button>81}82```8384### Server Action85```typescript86// Server Action in Server Component87async function createTodo(formData: FormData) {88 'use server'89 const title = formData.get('title') as string90 await db.todos.create({ title })91}9293export default function Page() {94 return <form action={createTodo}>...</form>95}96```9798## Reference Index99100| File | Topics |101|------|--------|102| [component-types.md](./references/component-types.md) | Server vs Client, boundary placement |103| [data-fetching.md](./references/data-fetching.md) | Async components, fetch caching, revalidation |104| [server-actions.md](./references/server-actions.md) | Form actions, mutations, revalidation |105| [patterns.md](./references/patterns.md) | Composition, prop drilling prevention |106| [streaming.md](./references/streaming.md) | Suspense, loading.tsx, progressive rendering |107108## Success Criteria109110Components are correct when:111- Default to Server (no "use client" unless needed)112- "use client" only for interactivity, browser APIs, hooks113- Data fetching in Server Components, not useEffect114- Server Actions for mutations, not API routes115- Client boundaries pushed down as far as possible116117---118> Converted and distributed by [TomeVault](https://tomevault.io/claim/jovermier) — claim your Tome and manage your conversions.119<!-- tomevault:4.0:skill_md:2026-04-13 -->