October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

Server Components vs. Client Components in Next.js: A Practical Mental Model

In Next.js, Server and Client Components are complementary parts of a component tree. Learn where the client boundary belongs, how initial HTML and hydration work, and how to keep data access and interaction in the right place.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In the Next.js App Router, pages and layouts are Server Components by default. Use a Client Component only where the interface needs browser capabilities—such as state, event handlers, effects, or browser APIs—and keep that boundary close to the interaction. The two types are designed to compose: server-prepared content can sit beside a small interactive part of the page.

Think in terms of a boundary, not two kinds of pages

A component’s label does not mean the whole page is “static” or “dynamic.” It describes the component’s execution environment and capabilities. Server Components do work on the server and contribute rendered output. A Client Component marks a module subtree that needs client-side JavaScript and browser behavior.

As an Amazon Associate I earn from qualifying purchases.

That boundary can divide work within one interface. A server-rendered article can include an interactive button; a mostly static navigation can contain a client-side search box. This is a composition model, not a choice between rendering an entire page on the server or in the browser.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In the App Router, layouts and pages are Server Components unless you opt into client code. Next.js recommends using Client Components when you need interactivity or browser APIs, rather than marking large areas of the application as client-side. Next.js: Server and Client Components and React: Server Components explain the distinction.

What happens when a route loads?

On an initial load, Next.js renders Server Components into the React Server Component Payload (RSC Payload). It uses the Client Components and that payload to prerender HTML. The browser can display that HTML before the interface is interactive, then use the payload to reconcile the component tree and hydrate Client Components. Hydration attaches event handlers and enables client behavior.

So “Client Component” does not mean “no initial HTML.” It means the component’s client capabilities require JavaScript and hydration. On later navigations, Next.js documents a different path: it can prefetch and cache the RSC Payload, and Client Components render on the client without server-rendered HTML for that navigation. These are route-loading details, not definitions of “server” and “client.” Next.js’s loading explanation covers both cases.

How do I decide which component belongs where?

Question Server Component Client Component
Does it need event handlers, local state, effects, or browser APIs? Not for those capabilities Yes; use client code for them
Does it need server-side data access, such as a database query? A natural place for that work Keep secrets and server-only query logic out of client code
Does it need to make the surrounding UI interactive? It can render the surrounding content It needs client JavaScript and hydration for its interactive behavior

Start with a Server Component, then introduce client code only for the part that needs it. For example, a page can fetch a post and render its title and body on the server, while a small LikeButton Client Component owns the click handler and local state. Pass the button the serializable data it needs, rather than moving the whole page into the client subtree.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Where should 'use client' go?

Put 'use client' at the top of the file that defines an interactive component. The directive establishes a boundary in the module dependency graph: the marked module and its imported dependencies become part of the client subtree. It is not a directive you need to repeat in every descendant.

That distinction explains why placing the directive high in the tree can pull more code into the client bundle than intended. If only a search box needs interaction, mark the search component’s module rather than the navigation layout that also contains a logo and static links. The smaller boundary keeps unrelated components out of that client module subtree.

The module graph is not the same thing as the rendered component tree. A Server Component can be rendered and passed to a Client Component as children or another prop. The client module must not import and invoke that Server Component itself. Props crossing from a Server Component to a Client Component must be serializable. See the React 'use client' reference for the boundary and serialization rules.

How should I fetch data and handle secrets?

An async Server Component can fetch data close to its source. Keeping database credentials and query logic in Server Components keeps them out of the client bundle, but server execution does not replace security controls: authenticate the user and authorize access to the requested data.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Data-fetching behavior depends on the current framework semantics. The current Next.js App Router guide says identical fetch requests in a React component tree are memoized by default, but requests are not cached by default and can block page rendering until they finish. Caching and Suspense-based streaming are options for changing how data is reused or how the page responds while data is pending. Check the Next.js Fetching Data guide for the framework’s current behavior rather than assuming every server request is cached.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What Server Components cannot do

  • Handle browser events: A Server Component cannot define an onClick handler. Put event handling in a Client Component.
  • Own client interaction state: Server Components cannot use client interaction APIs such as useState or maintain persistent component state.
  • Receive arbitrary props across the boundary: Props passed to a Client Component must be serializable.
  • Make data access automatically safe: Keep credentials server-side, and still authenticate and authorize requests.

Providers and third-party packages also fit this boundary model. A Server Component can render a provider imported from a Client Component module; Next.js recommends placing providers as deep as practical so more of the surrounding tree can remain eligible for static optimization. If a client-only third-party widget does not identify its own client requirement, wrap it in a small Client Component rather than converting its entire parent tree.

'use server' does not mean Server Component

React has no directive that marks a Server Component. 'use server' instead marks Server Functions: asynchronous server-side functions that client code can call. React says these functions are designed for mutations that update server-side state and are not recommended for data fetching. Treat their arguments as untrusted and authorize each mutation. See the React 'use server' reference.

The working rule

Keep data access and noninteractive output on the server where they benefit from server capabilities. Put browser-dependent behavior in the smallest useful Client Component boundary. Compose the two by passing serializable data or rendered server content across the boundary. This avoids the misleading shortcuts “server means static” and “client means no server-rendered HTML.”

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.