Run components on the server to eliminate client JavaScript and enable direct data access
When to Use
Components that fetch data and render it without client-side interactivity
Components that import large libraries (markdown parsers, date formatters) only needed for rendering
You need direct database or filesystem access without an API layer
Using Next.js App Router (RSC is the default) or another RSC-compatible framework
Instructions
Server Components are the default in Next.js App Router. Do not add 'use client' unless needed.
Server Components can:
async/await directly: const data = await db.query(...)
Import server-only libraries without impacting bundle size
Read environment variables and secrets directly
Add 'use client' directive at the top of a file when the component needs:
useState, useEffect, or any hooks
Browser APIs (window, document)
Event handlers (onClick, onChange)
Composition rule: Server Components can render Client Components, but Client Components cannot render Server Components (only pass them as children props).
Pass data from Server to Client Components as serializable props (no functions, classes, or non-serializable objects).
// Server Component (no 'use client')
async function ProductPage({ id }: { id: string }) {
const product = await db.products.findById(id); // direct DB access
return (
<div>
<h1>{product.name}</h1>
<AddToCartButton productId={id} /> {/* Client Component */}
</div>
);
}
// Client Component
'use client';
function AddToCartButton({ productId }: { productId: string }) {
return <button => addToCart(productId)}>Add to Cart</button>;
}
Details
RSC introduces a server/client component split at the file level. The framework serializes server-rendered output as a JSON-like payload (RSC payload) and sends it to the client for React to reconcile.
What RSC eliminates:
API routes for data fetching in many cases (direct DB access in server components)
Client-side waterfall requests (async server components fetch in parallel)
Bundle cost for render-only dependencies (they never reach the browser)
Common mistakes:
Adding 'use client' to every file "to be safe" — this negates RSC benefits
Trying to pass functions as props from server to client components — functions are not serializable
Using useEffect for data fetching in client components when a server component would work
Framework support (2024): Next.js App Router is the primary production implementation. Remix, Waku, and other frameworks have RSC support in various stages.
Read the instructions and examples in this document.
Apply the patterns to your implementation, adapting to your specific context.
Verify your implementation against the details and edge cases listed above.
Harness Integration
Type: knowledge — this skill is a reference document, not a procedural workflow.
No tools or state — consumed as context by other skills and agents.
Success Criteria
The patterns described in this document are applied correctly in the implementation.
Edge cases and anti-patterns listed in this document are avoided.
1---2name: react-server-components3description: React Server Components4---5# React Server Components67> Run components on the server to eliminate client JavaScript and enable direct data access89## When to Use1011- Components that fetch data and render it without client-side interactivity12- Components that import large libraries (markdown parsers, date formatters) only needed for rendering13- You need direct database or filesystem access without an API layer14- Using Next.js App Router (RSC is the default) or another RSC-compatible framework1516## Instructions17181. **Server Components are the default** in Next.js App Router. Do not add `'use client'` unless needed.192. Server Components can:20 - `async/await` directly: `const data = await db.query(...)`21 - Import server-only libraries without impacting bundle size22 - Read environment variables and secrets directly233. Add `'use client'` directive at the top of a file when the component needs:24 - `useState`, `useEffect`, or any hooks25 - Browser APIs (`window`, `document`)26 - Event handlers (`onClick`, `onChange`)274. **Composition rule:** Server Components can render Client Components, but Client Components cannot render Server Components (only pass them as `children` props).285. Pass data from Server to Client Components as serializable props (no functions, classes, or non-serializable objects).2930```typescript31// Server Component (no 'use client')32async function ProductPage({ id }: { id: string }) {33 const product = await db.products.findById(id); // direct DB access34 return (35 <div>36 <h1>{product.name}</h1>37 <AddToCartButton productId={id} /> {/* Client Component */}38 </div>39 );40}4142// Client Component43'use client';44function AddToCartButton({ productId }: { productId: string }) {45 return <button onClick={() => addToCart(productId)}>Add to Cart</button>;46}47```4849## Details5051RSC introduces a server/client component split at the file level. The framework serializes server-rendered output as a JSON-like payload (RSC payload) and sends it to the client for React to reconcile.5253**What RSC eliminates:**5455- API routes for data fetching in many cases (direct DB access in server components)56- Client-side waterfall requests (async server components fetch in parallel)57- Bundle cost for render-only dependencies (they never reach the browser)5859**Common mistakes:**6061- Adding `'use client'` to every file "to be safe" — this negates RSC benefits62- Trying to pass functions as props from server to client components — functions are not serializable63- Using `useEffect` for data fetching in client components when a server component would work6465**Framework support (2024):** Next.js App Router is the primary production implementation. Remix, Waku, and other frameworks have RSC support in various stages.6667## Source6869https://patterns.dev/react/react-server-components7071## Process72731. Read the instructions and examples in this document.742. Apply the patterns to your implementation, adapting to your specific context.753. Verify your implementation against the details and edge cases listed above.7677## Harness Integration7879- **Type:** knowledge — this skill is a reference document, not a procedural workflow.80- **No tools or state** — consumed as context by other skills and agents.8182## Success Criteria8384- The patterns described in this document are applied correctly in the implementation.85- Edge cases and anti-patterns listed in this document are avoided.
Run npx skillmds@latest add intense-visions/react-server-components in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
React Server Components It is listed under Web & Frontend on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
Intense-Visions (@intense-visions) published this skill. Their other Agent Skills are listed on their SkillMD profile.