nextjs-server-client-components
Guide for choosing between Server Components and Client Components in Next.js App Router. CRITICAL for useSearchParams (requires Suspense + 'use client'), navigation (Link, redirect, useRouter), cookies/headers access, and 'use client' directive. Activates when prompt mentions useSearchParams, Suspense, navigation, routing, Link component, redirect, pathname, searchParams, cookies, headers, async components, or 'use client'. Essential for avoiding mixing server/client APIs.
What this skill does
# Next.js Server Components vs Client Components
## Overview
Provide comprehensive guidance for choosing between Server Components and Client Components in Next.js App Router, including cookie/header access, searchParams handling, pathname routing, and React's 'use' API for promise unwrapping.
## TypeScript: NEVER Use `any` Type
**CRITICAL RULE:** This codebase has `@typescript-eslint/no-explicit-any` enabled. Using `any` will cause build failures.
**❌ WRONG:**
```typescript
function handleSubmit(e: any) { ... }
const data: any[] = [];
```
**✅ CORRECT:**
```typescript
function handleSubmit(e: React.FormEvent<HTMLFormElement>) { ... }
const data: string[] = [];
```
### Common Next.js Type Patterns
```typescript
// Page props
function Page({ params }: { params: { slug: string } }) { ... }
function Page({ searchParams }: { searchParams: { [key: string]: string | string[] | undefined } }) { ... }
// Form events
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => { ... }
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => { ... }
// Server actions
async function myAction(formData: FormData) { ... }
```
## When to Use This Skill
Use this skill when:
- Deciding whether to use Server or Client Components
- Accessing cookies, headers, or other server-side data
- Working with searchParams or route parameters
- Needing pathname or routing information
- Unwrapping promises with React 'use' API
- Debugging 'use client' boundary issues
- Optimizing component rendering strategy
## Core Decision: Server vs Client Components
### Default: Server Components
**All components in the App Router are Server Components by default.** No directive needed.
```typescript
// app/components/ProductList.tsx
// This is a Server Component (default)
export default async function ProductList() {
const products = await fetch('https://api.example.com/products');
const data = await products.json();
return (
<ul>
{data.map(product => (
<li key={product.id}>{product.name}</li>
))}
</ul>
);
}
```
**When to use Server Components:**
- Fetching data from APIs or databases
- Accessing backend resources (environment variables, file system)
- Processing sensitive information (API keys, tokens)
- Reducing client-side JavaScript bundle
- SEO-critical content rendering
- Static or infrequently changing content
**Benefits:**
- Zero client-side JavaScript by default
- Direct database/API access
- Secure handling of secrets
- Automatic code splitting
- Better initial page load performance
- Reduced bundle size
### Client Components: 'use client'
Add `'use client'` directive at the top of a file to make it a Client Component.
```typescript
// app/components/Counter.tsx
'use client';
import { useState } from 'react';
export default function Counter() {
const [count, setCount] = useState(0);
return (
<button onClick={() => setCount(count + 1)}>
Count: {count}
</button>
);
}
```
**When to use Client Components:**
- Need React hooks (useState, useEffect, useContext, etc.)
- Event handlers (onClick, onChange, onSubmit, etc.)
- Browser-only APIs (window, localStorage, navigator)
- Third-party libraries requiring browser environment
- Interactive UI elements (modals, dropdowns, forms)
- Real-time features (WebSocket, animations)
**Requirements for Client Components:**
- Must have `'use client'` directive at top of file
- Cannot use async/await directly in component
- Cannot access server-only APIs (cookies, headers)
- All imported components become Client Components
### ⚠️ CRITICAL: Server Components NEVER Need 'use client'
**Server Components are the DEFAULT. DO NOT add 'use client' unless you specifically need client-side features.**
**✅ CORRECT - Server Component with Navigation:**
```typescript
// app/page.tsx - Server Component (NO 'use client' needed!)
import Link from 'next/link';
import { redirect } from 'next/navigation';
export default async function Page() {
// Server components can be async
const data = await fetchData();
if (!data) {
redirect('/login'); // Server-side redirect
}
return (
<div>
<Link href="/dashboard">Go to Dashboard</Link>
<p>{data.content}</p>
</div>
);
}
```
**❌ WRONG - Adding 'use client' to Server Component:**
```typescript
// app/page.tsx
'use client'; // ❌ WRONG! Don't add this to server components!
export default async function Page() { // ❌ Will fail - async client components not allowed
const data = await fetchData();
return <div>{data.content}</div>;
}
```
**Server Navigation Methods (NO 'use client' needed):**
- `<Link>` component from `next/link`
- `redirect()` function from `next/navigation`
- Server Actions (see Advanced Routing skill)
**Client Navigation Methods (REQUIRES 'use client'):**
- `useRouter()` hook from `next/navigation`
- `usePathname()` hook
- `useSearchParams()` hook (also requires Suspense)
## Server Component Patterns
### Accessing Cookies
Use `next/headers` to read cookies in Server Components:
```typescript
// app/dashboard/page.tsx
import { cookies } from 'next/headers';
export default async function Dashboard() {
const cookieStore = await cookies();
const token = cookieStore.get('session-token');
if (!token) {
redirect('/login');
}
const user = await fetchUser(token.value);
return <div>Welcome, {user.name}</div>;
}
```
**Important Notes:**
- `cookies()` must be awaited in Next.js 15+
- Cookies are read-only in Server Components
- To set cookies, use Server Actions (see Advanced Routing skill)
- Cookie access is only available in Server Components
### Accessing Headers
```typescript
// app/api/route.ts or any Server Component
import { headers } from 'next/headers';
export default async function Page() {
const headersList = await headers();
const userAgent = headersList.get('user-agent');
const referer = headersList.get('referer');
return <div>User Agent: {userAgent}</div>;
}
```
### Using searchParams
Access URL query parameters directly in Server Components:
```typescript
// app/search/page.tsx
export default async function SearchPage({
searchParams,
}: {
searchParams: { q?: string; category?: string };
}) {
const query = searchParams.q || '';
const category = searchParams.category || 'all';
const results = await searchProducts(query, category);
return (
<div>
<h1>Search Results for: {query}</h1>
<p>Category: {category}</p>
<ProductList products={results} />
</div>
);
}
```
**Important Notes:**
- `searchParams` is only available in `page.tsx` files
- In Next.js 15+, `searchParams` must be awaited
- searchParams is NOT available in `layout.tsx`
- Use client-side `useSearchParams()` hook if needed in Client Components
**⚠️ CRITICAL WARNING - Next.js 15+ searchParams:**
When extracting parameters in Next.js 15+, you MUST use destructuring to keep the `searchParams` identifier visible in the same line as the parameter extraction. Do NOT use intermediate variables like `params` or `resolved` - this is an anti-pattern that breaks code readability and testing patterns.
**Async searchParams (Next.js 15+):**
```typescript
// app/search/page.tsx (Next.js 15+)
export default async function SearchPage({
searchParams,
}: {
searchParams: Promise<{ q?: string }>;
}) {
// BEST PRACTICE: Inline access keeps searchParams and parameter together on one line
const q = (await searchParams).q || '';
return <div>Search: {q}</div>;
}
```
**CRITICAL PATTERN REQUIREMENT:**
When extracting parameters from `searchParams`, **ALWAYS use inline access** to keep `searchParams` and the parameter name on the SAME LINE:
```typescript
// ✅ CORRECT: Inline access (REQUIRED PATTERN)
const name = (await searchParams).name || '';
// ✅ ALSO CORRECT: Multiple parameters
const category = (await searchParams).category || 'all';
const sort = (await searchParams).sort || 'asc';
// ❌ WRONG: Using intermediate variable separates searchPRelated in Design
contribute
IncludedLocal-only OSS contribution command center. Auto-refreshes the user's in-flight PR and issue state on invoke so conversations start with full context — no need to brief Claude on what's in flight. Helps the user find issues to contribute to on GitHub, builds per-repo dossiers of what each upstream expects (CLA, DCO, branch convention, AI policy, draft-first, review bots, issue templates), runs deterministic gates before any external action so AI-assisted contributions don't reach maintainers as slop. State is markdown-only: candidate files at ~/.contribute-system/candidates/, repo dossiers at ~/.contribute-system/research/, append-only event log at ~/.contribute-system/log.jsonl. No database, no cloud calls. Use when the user asks about their PRs / issues / contributions, wants to find new work to take on, claim an issue, build/refresh a repo's dossier, or draft a Design Issue or PR. Trigger with "/contribute", "what's my PR status", "find a contribution", "claim issue X", "draft a Design Issue for Y", "refresh dossier for Z".
architectural-analysis
IncludedUser-triggered deep architectural analysis of a codebase or scoped subtree across eight modes — information architecture, data flow, integration points, UI surfaces, interaction patterns, data model, control flow, and failure modes. This skill should be used when the user asks to "diagram this codebase," "map the architecture," "show the data flow," "give me an ERD," "trace control flow," "find the integration points," "verify the layout pattern," "audit the UX architecture," or any similar request whose primary deliverable is mermaid diagrams plus cited reports under docs/architecture/. Dispatches haiku/sonnet sub-agents in parallel for per-mode exploration, then verifies every citation mechanically before any node lands in a diagram. Not for one-off prose explanations of code (use code-explanation) or for high-level system design from scratch (use system-design).
mcp
IncludedModel Context Protocol (MCP) server development and tool management. Languages: Python, TypeScript. Capabilities: build MCP servers, integrate external APIs, discover/execute MCP tools, manage multi-server configs, design agent-centric tools. Actions: create, build, integrate, discover, execute, configure MCP servers/tools. Keywords: MCP, Model Context Protocol, MCP server, MCP tool, stdio transport, SSE transport, tool discovery, resource provider, prompt template, external API integration, Gemini CLI MCP, Claude MCP, agent tools, tool execution, server config. Use when: building MCP servers, integrating external APIs as MCP tools, discovering available MCP tools, executing MCP capabilities, configuring multi-server setups, designing tools for AI agents.
react-native-skia
IncludedDesign, build, debug, and optimise high-polish animated graphics in React Native or Expo using @shopify/react-native-skia, Reanimated, and Gesture Handler. Use when the user wants canvas-driven UI, shaders, paths, rich text, image filters, sprite fields, Skottie, video frames, snapshots, web CanvasKit setup, or performance tuning for custom motion-heavy elements such as loaders, hero art, cards, charts, progress indicators, particle systems, or gesture-driven surfaces. Also use when the user asks for fluid, glow, glass, blob, parallax, 60fps/120fps, or GPU-friendly animated effects in React Native, even if they do not explicitly say "Skia". Do not use for ordinary form/layout work with standard views.
plaid
IncludedProduct Led AI Development — guides founders from idea to launched product. Six capabilities: Idea (discover a product idea), Validate (pressure-test the idea against fatal flaws, problem reality, competition, and 2-week MVP feasibility), Plan (vision intake + document generation), Design (translate image references into a design.md spec), Launch (go-to-market strategy), and Build (roadmap execution). Use when someone says "PLAID", "plaid idea", "help me find an idea", "product idea", "idea from my business", "idea from my expertise", "plaid validate", "validate my idea", "pressure-test", "is this idea good", "find fatal flaws", "validate the problem", "plan a product", "define my vision", "generate a PRD", "product strategy", "plaid design", "design from image", "translate image to design", "create design.md", "extract design tokens", "plaid launch", "go-to-market", "launch plan", "GTM strategy", "launch playbook", "plaid build", "build the app", "start building", or "execute the roadmap".
nextjs-framer-motion-animations
IncludedAdds production-safe Motion for React or Framer Motion animations to Next.js apps, including reveal, hover and tap micro-interactions, whileInView, stagger, AnimatePresence, layout and layoutId transitions, reorder, scroll-linked UI, and lightweight route-content transitions. Use when the user asks to add, refactor, or debug Motion or Framer Motion in App Router or Pages Router codebases, especially around server/client boundaries, reduced motion, LazyMotion, bundle size, hydration, or route transitions. Avoid for GSAP-style timelines, WebGL or 3D scenes, heavy scroll storytelling, or CSS-only effects unless Motion is explicitly requested.