跳到正文
cccskills
免费在 GitHub 公开

nextjs-server-components

Build efficient React applications using Next.js Server Components that render on the server, reducing client bundle size, improving performance, and enabling direct database access. Use when fetching data server-side, reducing JavaScript bundle size, accessing databases directly in components, implementing streaming with Suspense, creating layouts that only render once, optimizing Core Web Vitals, or building SEO-friendly applications with server-first architecture.

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(1)

  • SKILL.md3.4 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Next.js Server Components - React Server Components Patterns

When to use this skill

  • Fetching data directly in Server Components
  • Reducing client-side JavaScript bundle size
  • Accessing databases directly without API routes
  • Implementing streaming rendering with Suspense
  • Creating layouts that render once and persist
  • Optimizing Largest Contentful Paint (LCP)
  • Building SEO-friendly server-rendered applications
  • Using server-only code (database queries, secrets)
  • Implementing server-side data transformations
  • Reducing Time to Interactive (TTI)
  • Building applications with zero client JS by default
  • Combining Server and Client Components effectively

When to use this skill

  • Building Next.js 13+ apps, optimizing component rendering, managing server/client boundaries.
  • When working on related tasks or features
  • During development that requires this expertise

Use when: Building Next.js 13+ apps, optimizing component rendering, managing server/client boundaries.

Key Concepts

Server Components (default in App Router):

  • Run only on server
  • Can directly access databases/APIs
  • Zero client JavaScript
  • Support async/await

Client Components ('use client'):

  • Interactive features
  • Browser APIs
  • React hooks (useState, useEffect, etc.)

Composition Pattern

// ✅ Server Component fetches data
// app/page.tsx
import { ClientComponent } from './ClientComponent';

export default async function Page() {
  const data = await fetchData(); // Server-side
  
  return (
    <div>
      <h1>Server Rendered: {data.title}</h1>
      <ClientComponent initialData={data} />
    </div>
  );
}

// ✅ Client Component handles interactivity
// app/ClientComponent.tsx
'use client';

export function ClientComponent({ initialData }) {
  const [count, setCount] = useState(0);
  
  return <button onClick={() => setCount(count + 1)}>{count}</button>;
}

Pass Server Components as Children

// ✅ Client Component with Server Component children
'use client';

export function ClientLayout({ children }: { children: React.ReactNode }) {
  const [isOpen, setIsOpen] = useState(false);
  
  return (
    <div>
      <button onClick={() => setIsOpen(!isOpen)}>Toggle</button>
      {isOpen && children}
    </div>
  );
}

// Usage - children can be Server Components!
<ClientLayout>
  <ServerDataComponent /> {/* Stays on server */}
</ClientLayout>

When to Use Client Components

Only use 'use client' when you need:

  • useState, useEffect, useContext
  • Browser APIs (localStorage, window)
  • Event handlers (onClick, onChange)
  • Custom hooks
  • Third-party libraries that use React hooks

Resources


Remember: Keep components server-side by default. Only add 'use client' when necessary for interactivity.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Build accessible web applications following WCAG 2.1/2.2 guidelines with proper semantic HTML, ARIA attributes, keyboard navigation, screen reader support, and inclusive design. Use when implementing ARIA labels and roles, ensuring keyboard navigation, supporting screen readers, providing text alternatives for images, managing focus, creating accessible forms, building inclusive UI components, testing with accessibility tools, meeting WCAG compliance levels, or designing for users with disabilities.

中文简介正在准备中。当前显示原文说明。

Fabric-Pro/fabric-oss32026年10月16日 更新

Guide for adding new OAuth-based integrations to Fabric. Use when implementing OAuth providers like Microsoft Teams, GitHub, Google Drive, Slack, or similar services that need OAuth 2.0 authentication for user data access.

中文简介正在准备中。当前显示原文说明。

Fabric-Pro/fabric-oss32026年10月16日 更新

Design clean, scalable, and maintainable REST and GraphQL APIs following industry best practices. Use when designing public or internal APIs, planning endpoint structures, defining request/response contracts, establishing versioning strategies, implementing authentication patterns, designing data models, creating API documentation, ensuring consistent error handling, optimizing for performance, or establishing service contracts between microservices.

中文简介正在准备中。当前显示原文说明。

Fabric-Pro/fabric-oss32026年10月16日 更新

Create professional, dark-themed architecture diagrams as standalone HTML files with SVG graphics. Use when the user asks for system architecture diagrams, infrastructure diagrams, cloud architecture visualizations, security diagrams, network topology diagrams, or any technical diagram showing system components and their relationships.

中文简介正在准备中。当前显示原文说明。

Fabric-Pro/fabric-oss32026年10月16日 更新

Create interactive, self-contained artifacts like mini-apps, visualizations, calculators, and tools that can be embedded or used standalone. Use when building interactive calculators, creating data visualizations, making mini web apps, building embeddable widgets, creating interactive demos, making tools for specific tasks, or generating standalone HTML/JS applications.

中文简介正在准备中。当前显示原文说明。

Fabric-Pro/fabric-oss32026年10月16日 更新

Set up something that runs on a schedule (a weekly report, a daily digest) as a scheduled workflow, change, pause or debug one, and build interactive pages (project artifacts and workspaces) that read live Fabric data. Use when the user asks for a recurring job, a status page, a dashboard or a page with buttons, or asks why one did not run.

中文简介正在准备中。当前显示原文说明。

Fabric-Pro/fabric-oss32026年10月16日 更新

查看 Fabric-Pro 的全部技能

报告此技能的问题