nextjs-best-practices
Master Next.js App Router Best Practices
Build production-ready Next.js applications with confidence. Learn Server Components, data fetching strategies, and routing patterns that scale.
下载技能 ZIP
在 Claude 中上传
前往 设置 → 功能 → 技能 → 上传技能
开启并开始使用
测试它
正在使用“nextjs-best-practices”。 Should I use useState in a Server Component?
预期结果:
No. Server Components cannot use useState, useEffect, or event handlers. These hooks require browser JavaScript. If you need state, mark the component with 'use client' or extract the interactive parts into a separate Client Component.
正在使用“nextjs-best-practices”。 How do I cache API responses in Next.js?
预期结果:
Use the fetch options: fetch(url, { next: { revalidate: 60 } }) caches for 60 seconds. For static content, omit revalidate for build-time caching. Use 'no-store' to disable caching entirely.
正在使用“nextjs-best-practices”。 What is the purpose of loading.tsx?
预期结果:
loading.tsx provides automatic loading states during navigation and data fetching. It renders while the new segment loads, improving perceived performance. Place it alongside page.tsx in any route segment.
安全审计
安全This skill is documentation-only content describing Next.js App Router best practices. Static analysis flagged 18 patterns (external_commands, weak cryptographic algorithms), but all are FALSE POSITIVES. The SKILL.md file contains only educational markdown content with code examples - no executable code, no shell commands, no cryptographic operations. Safe for publication.
质量评分
你能构建什么
Migrating from Pages to App Router
Transition existing Next.js projects to App Router architecture with proper Server Component patterns.
Building New Next.js Applications
Start new projects with correct folder structure, caching strategies, and component architecture from day one.
Code Review and Optimization
Audit existing codebases for anti-patterns like unnecessary Client Components or missing loading states.
试试这些提示
I have a component that displays user profile data and has a follow button. Should this be a Server Component or Client Component? Explain the reasoning.
What is the recommended fetch pattern for displaying product listings that should update every 5 minutes? Show the implementation.
How do I organize a dashboard with multiple sections (analytics, settings, users) that share a common layout but should not affect the URL structure?
Create a comment form using Server Actions. Include input validation with Zod, optimistic UI updates, and error handling. Show both the Server Component and Client Component code.
最佳实践
- Start with Server Components by default, add Client Components only when interactivity is required
- Use route groups with parentheses to organize routes without affecting the URL path
- Implement loading.tsx and error.tsx for every major route segment to handle pending and error states
避免
- Adding 'use client' to every component - this defeats the purpose of Server Components and increases bundle size
- Fetching data in Client Components instead of Server Components - causes waterfall requests and slower loads
- Skipping proper error boundaries - unhandled errors crash the entire application instead of showing fallback UI