React Server Components Explained in Plain English
On this page
- The idea in one picture
- Server Components vs Client Components
- A real example: a posts page that reads MongoDB
- Changing data with Server Functions
- Show slow parts later with Suspense
- The rules that matter
- Are Server Components the same as SSR?
- Common mistakes
- Do you need Server Components in a MERN app?
- Data fetching patterns that keep pages fast
- Migrating an existing React app
- Frequently asked questions
- Oh hi there 👋It’s nice to meet you.
- Sign up to receive awesome content in your inbox.
React Server Components (RSC) change where your components run. Some components run only on the server, fetch their own data, and send the browser finished UI instead of JavaScript. Others run in the browser as usual and handle clicks, typing and state. You decide which is which.
This guide explains the idea without jargon, shows a real example that reads from MongoDB, and lists the mistakes that trip up most developers.
The idea in one picture
Think of a restaurant. The kitchen (the server) prepares the food. The table (the browser) is where people eat and interact. Before Server Components, React sent the whole recipe and all the ingredients to the table and asked the guest to cook. With Server Components, the kitchen cooks most of the meal and sends out finished plates. Only the things the guest really needs to handle at the table, like the salt shaker, are sent as JavaScript.
In practice, that means less JavaScript to download, faster first paint on slow phones, and data fetching that happens next to your database instead of across the internet.
Server Components vs Client Components
| Server Component | Client Component | |
|---|---|---|
| Where it runs | Only on the server | On the server for the first HTML, then in the browser |
| How you mark it | Nothing: it is the default | 'use client' at the top of the file |
Can be async and await data |
Yes | No |
| Can read the database, files and secrets | Yes | No |
useState, useEffect, event handlers |
No | Yes |
Browser APIs such as window and localStorage |
No | Yes |
| Adds to the JavaScript bundle | No | Yes |
A real example: a posts page that reads MongoDB
Server Components are used through a framework. The most common one is the Next.js App Router, where every component is a Server Component unless you say otherwise. This page loads posts directly from MongoDB, with no API route in between:
// app/posts/page.jsx (a Server Component by default)
import { getDb } from '@/lib/db';
import LikeButton from './LikeButton';
export default async function PostsPage() {
const db = await getDb();
const posts = await db
.collection('posts')
.find({}, { projection: { title: 1, likes: 1 } })
.sort({ _id: -1 })
.limit(20)
.toArray();
return (
<ul>
{posts.map((post) => (
<li key={post._id.toString()}>
<h2>{post.title}</h2>
<LikeButton postId={post._id.toString()} initialLikes={post.likes ?? 0} />
</li>
))}
</ul>
);
}
The like button needs a click handler and state, so it is a Client Component:
// app/posts/LikeButton.jsx
'use client';
import { useState } from 'react';
import { likePost } from './actions';
export default function LikeButton({ postId, initialLikes }) {
const [likes, setLikes] = useState(initialLikes);
async function handleClick() {
setLikes((n) => n + 1); // update the screen right away
await likePost(postId); // save it on the server
}
return <button onClick={handleClick}>Like ({likes})</button>;
}
Only LikeButton is sent to the browser as JavaScript. The list, the database code and the MongoDB driver stay on the server.
Changing data with Server Functions
The likePost function above is a Server Function, also called a Server Action. The 'use server' directive lets a Client Component call it like a normal async function, while the code runs on the server:
// app/posts/actions.js
'use server';
import { ObjectId } from 'mongodb';
import { revalidatePath } from 'next/cache';
import { getDb } from '@/lib/db';
export async function likePost(postId) {
if (!ObjectId.isValid(postId)) throw new Error('Invalid post id');
const db = await getDb();
await db.collection('posts').updateOne(
{ _id: new ObjectId(postId) },
{ $inc: { likes: 1 } }
);
revalidatePath('/posts');
}
Treat every Server Function like a public API endpoint: anyone can call it with any arguments. Validate the input and check that the user is allowed to do the action.
Show slow parts later with Suspense
If one part of the page is slow, wrap it in Suspense. The rest of the page is sent right away, and the slow part streams in when its data is ready:
import { Suspense } from 'react';
import RevenueChart from './RevenueChart'; // an async Server Component
export default function Dashboard() {
return (
<main>
<h1>Dashboard</h1>
<Suspense fallback={<p>Loading revenue…</p>}>
<RevenueChart />
</Suspense>
</main>
);
}
The rules that matter
Put 'use client' as low in the tree as you can. The directive marks a boundary: that file and everything it imports becomes client code. Putting it on a layout or a page sends far more JavaScript than needed. Keep it on small, interactive leaves such as buttons, forms and dropdowns.
Props from server to client must be serializable. Strings, numbers, booleans, plain objects, arrays and dates are fine. Class instances such as a MongoDB ObjectId are not, which is why the example calls post._id.toString(). You can’t pass ordinary functions either, only Server Functions.
Client Components can’t import Server Components, but they can receive them as children. That lets an interactive wrapper, such as a modal, contain server-rendered content.
Keep secrets on the server. Add import 'server-only'; at the top of files that use API keys or database credentials. The build then fails if a Client Component ever imports them by mistake.
Are Server Components the same as SSR?
No, and this confuses a lot of people. Server-side rendering (SSR) turns components into HTML on the server, then sends the JavaScript for every component so the page can “hydrate” and become interactive. Server Components never send their JavaScript at all. Frameworks use both together: Server Components for most of the page, and SSR so Client Components also arrive as HTML.
Common mistakes
- Using a hook in a Server Component. Next.js shows an error saying the hook only works in a Client Component. Move the interactive part into its own file with
'use client'. - Fetching your own API route from a Server Component. You are already on the server, so query the database directly instead of making an extra HTTP request.
- Passing a whole MongoDB document to a Client Component. Convert
_idand other special types to strings, and pass only the fields the component needs. - Marking a whole page with
'use client'to make one button work. Split the button out instead.
Do you need Server Components in a MERN app?
If you build with Next.js, you are already using them. If your app is a classic MERN setup, with a Vite or Create React App frontend and a separate Express API, you don’t get Server Components and you don’t need them. That architecture is still a solid choice, especially for dashboards and apps behind a login, where SEO and first-load size matter less.
Data fetching patterns that keep pages fast
Fetch in parallel, not in a waterfall. When a Server Component awaits one request, then another, then a third, each waits for the previous one. If they don’t depend on each other, start them together:
export default async function Dashboard({ params }) {
const { id } = await params;
const [user, orders, notifications] = await Promise.all([
getUser(id),
getRecentOrders(id),
getNotifications(id),
]);
return <DashboardView user={user} orders={orders} notifications={notifications} />;
}
Fetch where the data is used. Instead of loading everything in the page and passing it down through many props, let each Server Component load its own data. Wrap slow ones in Suspense so they stream in without blocking the rest of the page.
Avoid repeated queries. When several components need the same data in one request, wrap the loader in React’s cache() function so the database is queried once per request:
import { cache } from 'react';
import { getDb } from '@/lib/db';
import { ObjectId } from 'mongodb';
export const getUser = cache(async (id) => {
const db = await getDb();
return db.collection('users').findOne({ _id: new ObjectId(id) }, { projection: { passwordHash: 0 } });
});
Notice the projection that leaves out the password hash. Even though Server Components run on the server, whatever you pass as props to a Client Component is sent to the browser. Select only the fields you intend to show.
Migrating an existing React app
You don’t have to rewrite everything at once. A practical path for a Next.js Pages Router or Create React App project is to move to the App Router route by route. Start with mostly static pages such as the blog, documentation or marketing pages, where Server Components bring the biggest speed gains. Keep complex interactive screens, such as editors and dashboards full of state, as Client Components at first. Over time, pull the static parts of those screens up into Server Components and leave only the interactive pieces on the client.
Frequently asked questions
Can I use React Server Components without Next.js?
Server Components need a framework or bundler that supports them. Next.js App Router is the most mature option today, and other frameworks are adding support. Plain Vite or Create React App projects can’t use them on their own.
Can a Server Component use useState?
No. State, effects and event handlers only work in Client Components. Move that logic into a small component marked with 'use client'.
Are Server Components good for SEO?
Yes. The server sends complete HTML, so search engines and AI crawlers can read the content without running JavaScript, and smaller bundles improve page speed.
Which React version includes Server Components?
Server Components became stable in React 19. Frameworks such as Next.js handle the setup for you.





1 comment