After this lesson, you will be able to: Understand React Server Components (RSC): when they run, what they can/can't do, vs Client Components.
RSC is React's biggest architectural shift since hooks. Next.js + many frameworks use them. Knowing the boundary is the senior signal.
Server Component: runs ON THE SERVER, never in the browser. Output is serialized HTML/JSX + props. Client Component: hydrates in the browser; can use useState, useEffect, event handlers. Default in Next.js App Router: Server. Opt into Client with `'use client'` directive at the top of a file.
Boundary at the leaf where interactivity starts.
// app/users/page.tsx, Server Component (no 'use client')import { db } from "@/lib/db";import { UserSearchInput } from "./UserSearchInput"; // Client Componentexport default async function UsersPage({ searchParams }) {const params = await searchParams;const users = await db.user.findMany({where: { name: { contains: params.q } },});return (<div><UserSearchInput /><ul>{users.map((u) => <li key={u.id}>{u.name}</li>)}</ul></div>);}// app/users/UserSearchInput.tsx, Client Component"use client";import { useState } from "react";import { useRouter } from "next/navigation";export function UserSearchInput() {const [q, setQ] = useState("");const router = useRouter();return <input value={q} onChange={(e) => { setQ(e.target.value); router.push(`?q=${e.target.value}`); }} />;}
CAN: await async data fetching directly. Access DB / files / env secrets. Render React components. CAN'T: use useState / useEffect / refs. Handle events. Use browser APIs (window, localStorage). Trickle the data: server pages fetch + pass to client components as props.
Forgetting 'use client' on components that need useState. Confusing build errors. Importing server code (DB clients) into client components. Bundler tries to bundle the server code. Marking everything 'use client' on the page. Defeats the RSC benefit. Calling server-only functions from client (use Server Actions instead).
Pick the right boundary.
Sign in and purchase access to unlock this lesson.