Deep Dive into React Server Components
1 min read117
Deep Dive into React Server Components
Let's deeply understand how server components work.
Client vs Server Components
| Feature | Server Component | Client Component |
|---|---|---|
| Bundle Size | Not included | Included |
| DB Access | Possible | Not possible |
| State | Not possible | Possible |
When to Use?
- Server Components: Data fetching, sensitive information
- Client Components: Interactions, event handlers
// Server component
async function ServerComponent() {
const data = await db.query('SELECT * FROM posts')
return <div>{data.map(post => <Post key={post.id} {...post} />)}</div>
}