Understanding the paradigm shift in React's architecture and what it means for your applications.
•Understanding the paradigm shift in React's architecture and what it means for your applications.
React Server Components (RSC) represent a significant shift in how we build React applications. By offloading rendering to the server, we can reduce bundle size and improve performance.
Here is a simple example of a Server Component that fetches data directly from a database:
async function BlogList() {
const posts = await db.posts.findMany();
return (
{posts.map(post => (
- {post.title}
))}
);
}
Notice how we use async/await directly in the component. This is only possible in Server Components.
If you need interactivity, like state or effects, you still use Client Components:
"use client";
import { useState } from "react";
export function Counter() {
const [count, setCount] = useState(0);
return (
);
}