nextjs-server-client-components

Guide Next.js Server and Client Component implementation in the App Router.

Updated Mar 11, 2026
One-click install
npx skills add https://github.com/sckroll/nextjs-mariadb-sample --skill nextjs-server-client-components-sckroll
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: nextjs-server-client-components
Source: https://github.com/sckroll/nextjs-mariadb-sample/tree/main/.agents/skills/nextjs-server-client-components
Command: npx skills add https://github.com/sckroll/nextjs-mariadb-sample --skill nextjs-server-client-components-sckroll

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill clarifies the complex decision-making process for choosing between Server Components and Client Components in Next.js, preventing common errors and optimizing application performance.

Core Features & Use Cases

  • Component Strategy: Guides developers on when to use Server Components (default) versus Client Components ('use client').
  • Data Fetching & APIs: Explains how to access cookies, headers, and searchParams in Server Components, and when to use client-side hooks like useSearchParams.
  • React 'use' API: Demonstrates leveraging the use API for promise unwrapping and context.
  • Use Case: You're building a Next.js app and are unsure whether to fetch user data directly in a page component or use a client-side hook. This Skill provides the decision framework and code examples to choose correctly.

Quick Start

Use the nextjs-server-client-components skill to understand how to access searchParams in a Next.js page.

Frequently Asked Questions about nextjs-server-client-components

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I know when to use Next.js Server Components versus Client Components in the App Router?

Use Next.js Server Components by default for data fetching and static rendering, and add the 'use client' directive to Client Components only when you need React hooks or browser APIs. This composition optimizes performance and prevents common anti-patterns.

How do I access cookies, headers, and searchParams in Next.js App Router pages?

Access cookies, headers, and searchParams directly as synchronous props within Next.js Server Components. If you need these values in Client Components, pass them down as props or use the client-side useSearchParams hook to avoid server-only API errors.

Can I use React hooks like useState and useEffect in Next.js Server Components?

No, you cannot use React hooks like useState or useEffect in Next.js Server Components because they execute exclusively on the server. You must define a Client Component with the 'use client' directive to utilize state and lifecycle hooks.

What is the best way to fetch data in Next.js App Router without blocking the UI?

Fetch data directly inside Next.js Server Components to execute on the server without blocking the client UI. You can leverage parallel data fetching and the React 'use' API for promise unwrapping to optimize rendering performance.

Why does my Next.js App Router build fail when calling server-only functions in interactive components?

Your Next.js build fails because interactive components are Client Components that lack server-side execution context. Move server-only API calls to parent Server Components and pass the resolved data down as props to avoid this limitation.