Agent skill
react-component-architecture-rsc
React Server Components vs Client Components decision framework, "use client" criteria, and composition patterns. Keywords: "server component", "client component", "use client", "rsc", "interactive", "useState"
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/react-component-architecture-rsc
SKILL.md
React Component Architecture - RSC
Core Principle: RSC as Default
All components in Next.js App Router are Server Components by default.
Server Components
- Async functions
- Can fetch data directly
- Cannot use state or effects
- Cannot use event handlers
- Cannot use browser APIs
- Run only on server
```tsx // Server Component (no 'use client') export default async function PostPage({ params }) { const post = await fetchPost(params.id);
return ( {post.title} {post.content} ); } ```
Client Components
Add `'use client'` directive when component needs:
- State: `useState`, `useReducer`
- Effects: `useEffect`, `useLayoutEffect`
- Event handlers: `onClick`, `onChange`
- Browser APIs: `window`, `localStorage`
- React Context consumers
```tsx 'use client';
import { useState } from 'react'; import { Button } from '@/components/ui/button';
export function LikeButton({ postId, initialLikes }) { const [likes, setLikes] = useState(initialLikes);
return ( <Button onClick={() => setLikes(likes + 1)}> 👍 {likes} </Button> ); } ```
Island Architecture Pattern
Keep Client Components small and at leaves:
```tsx // ✅ GOOD: Server parent, small Client leaf // app/posts/[id]/page.tsx (Server Component) export default async function PostPage({ params }) { const post = await fetchPost(params.id);
return ( {/* Server-rendered content */} {post.title} {post.content}
{/* Small interactive island */}
<LikeButton postId={post.id} initialLikes={post.likes} />
</article>
); }
// ❌ BAD: Entire page as Client Component 'use client'; export default function PostPage() { const [post, setPost] = useState(null);
useEffect(() => { fetchPost().then(setPost); }, []);
// All content client-rendered, larger bundle } ```
Data Flow: Server to Client
Pass data as serializable props:
```tsx // Server Component export default async function Page() { const data = await fetchData();
return <ClientComponent data={data} />; // ✅ Serializable }
// Cannot pass functions (unless Server Actions) <ClientComponent onClick={handleClick} /> // ❌ Function not serializable ```
Anti-Patterns
❌ `'use client'` on page.tsx/layout.tsx - Forces entire route client ❌ Data fetching in `useEffect` - Creates waterfall ❌ Large Client Components - Increases bundle size
✅ Server Components by default ✅ Extract only interactive parts to Client Components ✅ Fetch data in Server Components, pass as props
Token Estimate: ~3,000 tokens
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?