How I think about React Server Components

React Server Components have been talked about since 2020, but for most of us they became real in May, when Next. js 13. 4 marked the App Router as stable.

React Server Components have been talked about since 2020, but for most of us they became real in May, when Next.js 13.4 marked the App Router as stable. They’re also the most confusing React change since hooks. Here’s the mental model that made it click.

Two kinds of components in one tree

In the App Router, every component is a Server Component by default. It runs on the server (at build time or per request), and only its rendered output is sent to the browser. Its code never is.

That means a Server Component can do things a normal component can’t:

// app/products/page.tsx (a Server Component)
import { db } from '@/lib/db';
import AddToCart from './add-to-cart';

export default async function ProductsPage() {
  const products = await db.product.findMany();

  return (
    <ul>
      {products.map((p) => (
        <li key={p.id}>
          {p.name} <AddToCart productId={p.id} />
        </li>
      ))}
    </ul>
  );
}

It’s async. It talks to the database directly. There’s no API route, no useEffect fetch, no loading state for the first render. The database client never ends up in the JavaScript bundle.

What it can’t do is anything interactive. No useState, no useEffect, no onClick. For that you need a Client Component, marked with ‘use client’ at the top of the file:

// app/products/add-to-cart.tsx
'use client';

import { useState } from 'react';

export default function AddToCart({ productId }: { productId: string }) {
  const [added, setAdded] = useState(false);

  async function add() {
    await fetch('/api/cart', { method: 'POST', body: JSON.stringify({ productId }) });
    setAdded(true);
  }

  return <button onClick={add}>{added ? 'Added' : 'Add to cart'}</button>;
}

The name “Client Component” is a bit misleading. It still renders to HTML on the server first, like any SSR component always has. The difference is that its code is also shipped to the browser so it can hydrate and become interactive.

‘use client’ marks a boundary, not a component

This was my biggest misunderstanding. ‘use client’ doesn’t mean “this one component runs on the client”. It means “this file, and everything it imports, is client code”. It’s a door between two worlds.

So if a Client Component imports another component, that one becomes client code too, even if it never needed any interactivity. If you put ‘use client’ high up in the tree, say on a layout, you’ve quietly turned most of the app back into a regular client-side React app.

The practical rule: push ‘use client’ as far down as you can. Make the button a Client Component, not the whole product list.

Passing server content through client components

But what if you need an interactive wrapper, like tabs or a modal, around content that should stay on the server? A Client Component can’t import a Server Component, but it can receive one as children:

// app/dashboard/page.tsx (Server Component)
import Tabs from './tabs'; // 'use client'
import RevenueReport from './revenue-report'; // Server Component

export default function Dashboard() {
  return (
    <Tabs>
      <RevenueReport />
    </Tabs>
  );
}

RevenueReport is rendered on the server and passed into Tabs as already-rendered output. Tabs can show or hide it, but it never runs its code. Once this pattern clicked, most of my “how do I do X” questions went away.

Props have to cross the network

Everything you pass from a Server Component to a Client Component gets serialized and sent to the browser. Strings, numbers, plain objects and arrays are fine. Functions aren’t:

// Server Component
<AddToCart productId={p.id} onAdded={() => console.log('added')} />
// Error: Functions cannot be passed directly to Client Components...

Class instances and things like database records with methods won’t survive either. Pass plain data.

And be careful about what you pass. Whatever goes into a Client Component’s props ends up in the page source. If you hand over a full user object from the database, the password hash goes with it. Pick the fields you need.

For code that must never reach the browser, like a module that reads secret keys, the server-only package makes the build fail if a Client Component ever imports it:

// lib/payments.ts
import 'server-only';

Things that tripped me up

  • Context providers are client code. createContext doesn’t work in Server Components. Put your providers in a small ‘use client’ file and wrap children with it in the root layout.
  • Next.js caches fetch by default. In Next 13, a fetch in a Server Component is cached unless you opt out with { cache: ‘no-store’ } or a revalidate option. Data that seems stuck is often this.
  • Server Actions are still experimental. You can write ‘use server’ functions and call them from forms, but in 13.4 they’re behind an experimental flag. For production mutations I still use route handlers for now.

When it’s worth it

For pages that are mostly content, like dashboards, product listings or docs, the result is less JavaScript in the browser and simpler data loading. For an app that’s interactive everywhere, like an editor, most components will be Client Components anyway, and the benefit is smaller. Either way, the model to keep in mind is simple: Server Components fetch and render, Client Components handle interaction, and ‘use client’ is the line between them.