React Server Components: The Next Evolution of Frontend
Comments
Sign in to join the conversation
Sign in to join the conversation
React Server Components (RSC) represent arguably the biggest shift in the React ecosystem since the introduction of Hooks. They fundamentally change how we build React applications by blurring the line between the client and the server. But what exactly are they, and how do they differ from Server-Side Rendering (SSR)?
In CSR, the user downloads a large JavaScript bundle. The browser executes this bundle to render the UI and then fetches data from an API. This leads to:
SSR solves the initial HTML render. The server renders the component tree to HTML and sends it to the client. However, the client still needs to download the JavaScript (hydration) for those components to become interactive. SSR is primarily about the initial load
React Server Components allow you to render components exclusively on the server.
Key Characteristics:
moment.js or a markdown parser) in a Server Component, the user downloads precisely 0 bytes of it.To distinguish between the two environments, Next.js (and React) introduced directives:
useState, useEffect, or event listeners (onClick) here.'use client' at the top of the file to use interactivity (state, effects, browser APIs). These are hydrated on the client.The magic happens when you interleave them. A Server Component can fetch data and pass it as props to a Client Component.
// UserProfile.tsx (Server Component)
import db from './db';
import InteractiveButton from './InteractiveButton';
async function UserProfile({ userId }) {
const user = await db.user.findUnique({ id: userId });
return (
<div>
<h1>{user.name}</h1>
userReact Server Components allow developers to get the best of both worlds: the rich interactivity of client-side apps with the performance and simple data access of server-rendered templates. While the paradigm shift requires unlearning some old habits, the benefits for performance and developer experience are substantial.