React Server Components Explained: A Guide for Developers in Estonia
React Server Components render on the server and send no component code to the browser. Learn how they differ from Client Components and when to use each one.
Updated , 4 min read, by the React.ee editorial team
The short answer
- Server Components render on the server and their code is never sent to the browser, which reduces client JavaScript.
- Client Components, marked with the use client directive, handle state, effects and event handlers.
- Keep components on the server by default and move only the interactive parts to the client.
React Server Components are components that render only on the server, at build time or for each request, and send their rendered output to the browser without sending their own code. They can read data directly from a database or an API, and they keep secrets and heavy dependencies off the client. Interactive parts of the page are written as Client Components. Server Components are stable in React 19 and are the default in the Next.js App Router.
What problem do Server Components solve?
In a traditional client-rendered React application, every component ships to the browser as JavaScript, whether or not it is interactive. A page that mostly displays content still downloads and runs code for all of it, and then often makes further requests to fetch its data.
Server Components change the default. Components that only display things run on the server, close to the data, and the browser receives the result. Only the parts that are truly interactive are shipped as JavaScript. This means less code to download and run, fewer request round trips and simpler data loading.
How do Server and Client Components differ?
| Server Component | Client Component | |
|---|---|---|
| Where it runs | On the server only | Pre-rendered on the server, then runs in the browser |
| Code sent to the browser | No | Yes |
| Marked with | Nothing; it is the default in supporting frameworks | The use client directive at the top of the file |
| Can be an async function | Yes | No |
| Direct access to database, file system and secrets | Yes | No |
| useState, useEffect and other stateful hooks | No | Yes |
| Event handlers such as onClick | No | Yes |
| Browser APIs | No | Yes |
One point is often misunderstood: Client Components are not rendered only in the browser. In frameworks such as Next.js they are still rendered to HTML on the server for the first load, and then hydrated in the browser so they become interactive. The word "client" means that their code is also sent to and run on the client.
What does the use client directive do?
Placing "use client" at the top of a file marks a boundary. That module, and everything it imports, becomes part of the client bundle. You do not need to add the directive to every interactive file, only to the entry points where server-rendered code first hands over to client code.
There is no matching directive for Server Components. The similarly named "use server" directive does something different: it marks Server Functions, which are covered below.
How do the two kinds work together?
A Server Component can import and render a Client Component and pass it props. Those props cross from server to browser, so they must be serialisable: strings, numbers, plain objects, arrays and similar values, but not ordinary functions or class instances.
A Client Component cannot import a Server Component, because anything imported into a client module becomes client code. It can, however, receive Server Components as children or other props. This is the pattern that keeps most of a page on the server:
// A Server Component
export default async function ProductPage({ id }) {
const product = await getProduct(id);
return (
<Tabs>
<ProductDetails product={product} />
</Tabs>
);
}
Here Tabs can be a Client Component that manages which tab is open, while ProductDetails remains a Server Component passed in as children. The interactive shell is small, and the content inside it ships no JavaScript.
How is data fetched?
A Server Component can be an async function and await data directly, with no effect and no separate API endpoint for the page's own data. The data is fetched on the server and the component renders with it.
Slow parts can be wrapped in a Suspense boundary. The framework streams the rest of the page immediately and sends the slow section when it is ready, showing a fallback in the meantime.
What are Server Functions?
Server Functions, previously known as Server Actions, are async functions marked with "use server" that run on the server but can be called from the client. They are the standard way to handle mutations: you pass one to a form's action prop or call it from an event handler, and the framework makes the request for you.
They combine with React 19's form features, such as useActionState for the result and pending state of a submission, and useOptimistic for immediate feedback.
Treat every Server Function as a public endpoint. It can be invoked with any arguments, so validate the input and check that the user is authorised inside the function itself.
When should a component be a Client Component?
Make it a Client Component when it needs any of the following:
- state or effects;
- event handlers for clicks, input or gestures;
- browser APIs such as local storage or geolocation;
- a third-party library that depends on any of the above.
Keep everything else on the server: layouts, text content, data display, and anything that touches a database or a secret.
A practical rule: start with Server Components and push the use client boundary as far down the tree as you can. A page with one interactive button should not become a Client Component as a whole. Extract the button.
What are the common mistakes?
- Adding use client everywhere. This recreates a client-rendered application and gives up the benefit.
- Passing functions as props from server to client. Ordinary functions are not serialisable. Pass a Server Function, or define the handler in the Client Component.
from our network