Distinguish Server and Client Components
Separate component evaluation from HTML rendering
React Server Components (RSC) let a compatible integration evaluate selected components on the server or at build time. Their source modules do not need to be delivered to the browser. The integration transports a representation of their rendered output and references to interactive client components. SSR instead produces HTML; a framework may use both RSC and SSR, then hydrate the interactive client portions. A Client Component may participate in initial HTML rendering on the server and subsequently run in the browser. It is not necessarily browser-only. These examples use React 19 concepts and require a reviewed, patched RSC integration. Ordinary Vite plus React DOM does not implement this transport. No RSC server is included or running.
import React from 'react';import ShelfToggle from './c40-l01-s06.jsx';async function readShelf(){return [{id:'b1',title:'Moss atlas'},{id:'b2',title:'Garden birds'}];}export default async function Shelf(){ const books=await readShelf(); return <section><h2>Field library</h2><ShelfToggle count={books.length}><ul>{books.map(b=><li key={b.id}>{b.title}</li>)}</ul></ShelfToggle></section>;}The server component awaits a fixed in-memory result. Its output includes the heading and a client toggle with a numeric count and a server-created list as children. The server module has no state hook. In a real application, a data source may live behind a server-only dependency, with access checks at the data boundary. No real database is needed here. The next module is the matching client boundary. The list is initially visible and the button displays Hide 2 books.
Introduce an interactive boundary
'use client';import React,{useState} from 'react';export default function ShelfToggle({count,children}){ const [open,setOpen]=useState(true); return <div><button type="button" aria-expanded={open} onClick={()=>setOpen(v=>!v)}>{open?'Hide':'Show'} {count} books</button>{open&&children}</div>;}The directive is a quoted module prologue before imports. It identifies a client entry and affects its transitive imports in an RSC-aware build; it is not an instruction for every component in the JSX tree to execute on the client. The button changes local state without requesting another server evaluation merely because it hides or shows children. The client module does not import the server component. Passing server-rendered content as a child is supported composition; importing server-only code directly into the client graph is not the way to achieve it. A shared module without a directive may be evaluated in either graph depending on imports.
Compose independent asynchronous sections
import React,{Suspense} from 'react';import Shelf from './c40-l01-s03.jsx';export default function LibraryPage(){ return <main><h1>Library guide</h1><Suspense fallback={<p role="status">Preparing shelf...</p>}><Shelf/></Suspense><p>Ask the desk for loan information.</p></main>;}If the shelf is pending, the integration can present its fallback while other content is available. The mock read resolves immediately, so a visible loading interval is not guaranteed. The final page should show Library guide and Field library with the two books. React can stream asynchronous RSC content in a compatible integration; SSR HTML streaming is a related but different layer. Server Components have no special use server directive: that directive marks callable Server Functions. Keep server-only dependencies outside client bundles. Use framework-supported server-only guards and inspect production outputs before release. Practice: draw the module graph and component tree separately, then explain which state stays in the browser.