Overview
React Server Components (RSC) enable you to render components on the server, reducing JavaScript sent to the browser and improving performance significantly.
Key Benefits
- Zero JavaScript: Server components don't ship JavaScript to the client
- Direct Database Access: Query databases without API routes
- Secret Safety: API keys stay on the server
- Performance: Faster initial page load and better Core Web Vitals
- Streaming: Progressive rendering with Suspense
Quick Start
By default, all components in the app/ directory are Server Components:
// app/page.tsx - Server Component by default
export default async function Page() {
const data = await fetch('https://api.example.com/data')
return <div>{/* Your content */}</div>
}
Client Components
Mark components that need interactivity with 'use client':
'use client'
import { useState } from 'react'
export default function Counter() {
const [count, setCount] = useState(0)
return <button onClick={() => setCount(count + 1)}>{count}</button>
}
Best Practices
- Keep data fetching on server - Reduce client-side queries
- Use Suspense - Stream UI progressively to users
- Minimize client boundaries - Keep
'use client'at leaf components - Cache aggressively - Use Next.js caching strategies
Proper use of Server Components can reduce your bundle size by 40-60%.