Skip to content

Server Components

In one line

Server Components run on the server, never ship to the client — reducing bundle size and enabling direct backend access.

In simple words

Server Components (React 18, popularized by Next.js App Router) render exclusively on the server. They:

  1. Send HTML, not JS — zero client bundle cost for server components
  2. Access backend directly — can query databases, read files, use secrets
  3. Can be async — await data fetching directly in the component
  4. Cannot use hooks — no useState, useEffect, event handlers
  5. Can import client components — mix server and client in the same tree

Mark client components with "use client". Server components are the default. This paradigm shifts heavy data fetching and static rendering to the server, keeping the client bundle small.

Example

jsx
// Server Component (default — no "use client")
import { db } from "./database";

async function ProductList() {
  // Direct database access — no API needed
  const products = await db.query("SELECT * FROM products");
  return (
    <ul>
      {products.map(p => (
        <li key={p.id}>
          {p.name} - ${p.price}
          <AddToCartButton id={p.id} /> {/* Client component */}
        </li>
      ))}
    </ul>
  );
}

// Client Component
"use client";
function AddToCartButton({ id }) {
  const [added, setAdded] = useState(false);
  return <button onClick={() => setAdded(true)}>Add</button>;
}

Server Component fetches data directly from DB (no API). AddToCartButton is a Client Component with interactivity. Only the button ships JS to the client.

Common confusions

  • Confused with: SSR

    The difference: SSR renders components to HTML on the server but still ships the component JS to the client for hydration. Server Components never ship their JS to the client — they send only HTML. SSR hydrates; Server Components don't. They can be combined: SSR + Server Components.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary