wsimmonds/claude-nextjs-skills/nextjs-server-client-components
Claude Code and agent skill by wsimmonds/claude-nextjs-skills
- community
- ext:[{"type":"context","description":"Custom context provider definitions"}]
Checking that the SKILL.md file is still in the repository.
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.
Install
npx vskill@latest install wsimmonds/claude-nextjs-skills/nextjs-server-client-componentsSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
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:
✅ CORRECT:
Common Next.js Type Patterns
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.
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.
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:
❌ WRONG - Adding 'use client' to Server Component:
Server Navigation Methods (NO 'use client' needed):
<Link>component fromnext/linkredirect()function fromnext/navigation- Server Actions (see Advanced Routing skill)
Client Navigation Methods (REQUIRES 'use client'):
useRouter()hook fromnext/navigationusePathname()hookuseSearchParams()hook (also requires Suspense)
Server Component Patterns
Accessing Cookies
Use next/headers to read cookies in Server Components:
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
Using searchParams
Access URL query parameters directly in Server Components:
Important Notes:
searchParamsis only available inpage.tsxfiles- In Next.js 15+,
searchParamsmust 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+):
CRITICAL PATTERN REQUIREMENT:
When extracting parameters from searchParams, ALWAYS use inline access to keep searchParams and the parameter name on the SAME LINE:
Why inline access:
- Keeps
searchParamsidentifier visible on the same line as parameter extraction - Makes the relationship between URL parameter and variable explicit
- Satisfies code review and testing patterns that check for proper searchParams usage
Using pathname and Route Information
In Server Components (page.tsx):
Async params (Next.js 15+):
In Client Components:
Use hooks from next/navigation:
⚠️ CRITICAL: useSearchParams ALWAYS Requires Suspense
When using `useSearchParams()` hook, you MUST:
- Add
'use client'directive at the top of the file - Wrap the component in a Suspense boundary
This is a Next.js requirement - failing to do both will cause errors.
✅ CORRECT Pattern:
❌ WRONG - Missing 'use client':
❌ WRONG - Missing Suspense wrapper:
React 'use' API for Promise Unwrapping
The React use API allows reading promises and context in both Server and Client Components.
Using 'use' with Promises
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingnextjs-server-client-components/SKILL.md
Popularity
- Repository stars
- 74
- Repository forks
- 9
- 7-day trend score
- 22
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 16 Mar 2026, 7 months ago.
Extension points
contextCustom context provider definitions
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/wsimmonds/claude-nextjs-skills/nextjs-server-client-components)