The Codex / Technologies / React / Server Components & Next.js

Server Components & Next.js

The modern full-stack React model - what Server Components are, how they differ from Client Components, and why Next.js exists.

What it is, in plain English: React Server Components (RSC) are components that render on the SERVER and send the result to the browser as a compact format -- not as JavaScript the browser has to execute. They can directly access databases and the filesystem, never ship their code to the client, and reduce the JavaScript bundle size. Client Components (marked with 'use client') are the React you already know -- they run in the browser and can use hooks and interactivity. Next.js is the most popular framework implementing this model.

React that runs on the server, not just the browser

Everything covered so far runs in the browser -- React renders, useState updates, useEffect fires, all client-side. React Server Components introduce a second kind of component that runs ONLY on the server, never shipping its code to the browser at all.

The two kinds of components

// SERVER COMPONENT (the default in Next.js App Router) -- no directive needed:
// app/page.js
async function HomePage() {
  // Can directly query a database, read files, use server-only secrets:
  const posts = await db.posts.findMany();

  return (
    <div>
      <h1>Blog</h1>
      {posts.map(post => <article key={post.id}>{post.title}</article>)}
    </div>
  );
}
// This component's CODE never reaches the browser -- only its rendered HTML output.
// No useState, no onClick, no useEffect allowed here -- it's not interactive.
// CLIENT COMPONENT -- needs the "use client" directive at the top of the file:
"use client";

import { useState } from "react";

function LikeButton() {
  const [liked, setLiked] = useState(false);   // hooks work here

  return (
    <button onClick={() => setLiked(!liked)}>
      {liked ? "❤️ Liked" : "🤍 Like"}
    </button>
  );
}
// THIS component's code DOES ship to the browser, because it needs
// to run there to handle clicks and manage state.

Why this distinction exists

// Before Server Components, ALL React code shipped to the browser as JavaScript,
// even components that just fetched data and displayed it -- no interactivity needed.
// This meant: bigger JS bundles, slower initial load, and a round-trip
// (fetch on the server for an API, then fetch AGAIN from the browser).

// Server Components fix this:
// - Zero JavaScript shipped for non-interactive parts of the page
// - Direct backend access (database, filesystem) -- no API layer needed
// - Smaller bundles = faster page loads
// - Secrets (API keys, DB credentials) never reach the browser

What Next.js actually is

// Next.js is a FRAMEWORK built on React that adds:
// - File-based routing (app/products/page.js = /products route)
// - Server Components by default (App Router)
// - Built-in data fetching, image optimization, font optimization
// - API routes (app/api/users/route.js)
// - Deployment optimizations (especially on Vercel)

// React alone = just the UI library (components, hooks, rendering)
// Next.js = React + routing + server rendering + build tooling + conventions
Try It Yourself (JSX)

Official Sources

The Codex links only to official documentation. No third-party tutorials.