nextjs-server-client-components

wsimmonds/claude-nextjs-skills · updated Apr 8, 2026

MDX-style export adds YAML metadata + attribution linking explainx.ai and this canonical listing URL.

$npx skills add https://github.com/wsimmonds/claude-nextjs-skills --skill nextjs-server-client-components
0 commentsdiscussion
summary

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.

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:

function handleSubmit(e: any) { ... }
const data: any[] = [];

✅ CORRECT:

function handleSubmit(e: React.FormEvent<HTMLFormElement>) { ... }
const data: string[] = [];

Common Next.js Type Patterns

// 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.

// 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.

// 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:

// 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:

// 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:

// 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 a
how to use nextjs-server-client-components

How to use nextjs-server-client-components on Cursor

AI-first code editor with Composer

1

Prerequisites

Before installing skills in Cursor, ensure your development environment meets these requirements:

  • Cursor installed and configured on your development machine
  • Node.js version 16.0+ with npm package manager (verify with node --version)
  • Active project directory or workspace where you want to add nextjs-server-client-components
2

Execute installation command

Execute the skills CLI command in your project's root directory to begin installation:

$npx skills add https://github.com/wsimmonds/claude-nextjs-skills --skill nextjs-server-client-components

The skills CLI fetches nextjs-server-client-components from GitHub repository wsimmonds/claude-nextjs-skills and configures it for Cursor.

3

Select Cursor when prompted

The CLI will show a list of available agents. Use arrow keys to navigate and space to select Cursor:

◆ Which agents do you want to install to?
│ ── Universal (.agents/skills) ── always included ────
│ • Amp
│ • Antigravity
│ • Cline
│ • Codex
│ ●Cursor(selected)
│ • Cursor
│ • Windsurf
4

Verify installation

Confirm successful installation by checking the skill directory location:

.cursor/skills/nextjs-server-client-components

Reload or restart Cursor to activate nextjs-server-client-components. Access the skill through slash commands (e.g., /nextjs-server-client-components) or your agent's skill management interface.

Security & Verification Notice

We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.

Skills execute code in your development environment. Always verify the publisher's identity, review recent commits, and test in isolated environments before production deployment.

List & Monetize Your Skill

Submit your Claude Code skill and start earning

GET_STARTED →

Use Cases

Task Automation & Efficiency

Automate repetitive workflows and reduce manual effort

Example

Generate reports, summarize documents, draft communications

Save 3-5 hours per week on routine tasks

Knowledge Enhancement

Learn new skills, understand complex topics, get expert guidance

Example

Explain concepts, provide examples, suggest learning resources

Accelerate learning and skill development by 2x

Quality Improvement

Enhance output quality through reviews, suggestions, and refinements

Example

Review drafts, suggest improvements, catch errors

Improve work quality by 30-40% with less effort

Implementation Guide

Prerequisites

  • Claude Desktop or compatible AI client with skill support
  • Clear understanding of task or problem to solve
  • Willingness to iterate and refine outputs

Time Estimate

15-45 minutes depending on use case complexity

Installation Steps

  1. 1.Install skill using provided installation command
  2. 2.Test with simple use case relevant to your work
  3. 3.Evaluate output quality and relevance
  4. 4.Iterate on prompts to improve results
  5. 5.Integrate into regular workflow if valuable

Common Pitfalls

  • Expecting perfect results without iteration
  • Not providing enough context in prompts
  • Using skill for tasks outside its intended scope
  • Accepting outputs without review and validation

Best Practices

✓ Do

  • +Start with clear, specific prompts
  • +Provide relevant context and constraints
  • +Review and refine all outputs before using
  • +Iterate to improve output quality
  • +Document successful prompt patterns

✗ Don't

  • Don't use without understanding skill limitations
  • Don't skip validation of outputs
  • Don't share sensitive information in prompts
  • Don't expect skill to replace human judgment

💡 Pro Tips

  • Be specific about desired format and style
  • Ask for multiple options to choose from
  • Request explanations to understand reasoning
  • Combine AI efficiency with human expertise

When to Use This

✓ Use When

Use when skill capabilities match your task, clear ROI on time saved, and you can validate outputs. Best for repetitive tasks, learning, and quality improvement.

✗ Avoid When

Avoid when task requires deep expertise you can't validate, involves sensitive decisions, or when learning process is more valuable than speed of completion.

Learning Path

  1. 1Familiarize yourself with skill capabilities and limitations
  2. 2Start with low-risk, non-critical tasks
  3. 3Progress to more complex and valuable use cases
  4. 4Build expertise through regular use and experimentation

Discussion

Product Hunt–style comments (not star reviews)
  • No comments yet — start the thread.
general reviews

Ratings

4.737 reviews
  • Isabella Huang· Dec 28, 2024

    I recommend nextjs-server-client-components for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.

  • Chaitanya Patil· Dec 24, 2024

    Registry listing for nextjs-server-client-components matched our evaluation — installs cleanly and behaves as described in the markdown.

  • Soo Zhang· Dec 24, 2024

    nextjs-server-client-components fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

  • Pratham Ware· Dec 20, 2024

    nextjs-server-client-components is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.

  • Ira Liu· Nov 23, 2024

    nextjs-server-client-components is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.

  • Lucas Harris· Nov 19, 2024

    nextjs-server-client-components fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

  • Piyush G· Nov 15, 2024

    nextjs-server-client-components reduced setup friction for our internal harness; good balance of opinion and flexibility.

  • Ira Farah· Oct 14, 2024

    Useful defaults in nextjs-server-client-components — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.

  • Nia Kapoor· Oct 10, 2024

    Registry listing for nextjs-server-client-components matched our evaluation — installs cleanly and behaves as described in the markdown.

  • Shikha Mishra· Oct 6, 2024

    I recommend nextjs-server-client-components for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.

showing 1-10 of 37

1 / 4