nextjs-data-fetching

Orchestrate server and client data fetching in Next.js applications.

Updated Sep 6, 2024
One-click install
npx skills add https://github.com/Jaylaelike/pm25-interactive-thaipbs-app --skill nextjs-data-fetching
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: nextjs-data-fetching
Source: https://github.com/Jaylaelike/pm25-interactive-thaipbs-app/tree/main/.claude/skills/nextjs-data-fetching
Command: npx skills add https://github.com/Jaylaelike/pm25-interactive-thaipbs-app --skill nextjs-data-fetching

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill provides a complete Next.js data-fetching system that coordinates server and client data loading across app routes, API routes, and components, reducing boilerplate and complexity.

Core Features & Use Cases

  • Server Components Data Fetching: fetch data in server components with built-in caching and error handling.
  • Parallel & Sequential Fetching: orchestrate multiple requests efficiently using Promise.all and sequential flows.
  • Streaming with Suspense: progressively render data using Suspense boundaries for better UX.
  • Route Handlers (API routes): create API endpoints tied to Next.js routing.
  • Client-side Fetching: integrate SWR or TanStack Query for dynamic UI updates.
  • Static Generation & Revalidation: leverage generateStaticParams, ISR, and revalidation strategies.
  • Error Handling & Validation: consistent error boundaries and type-safe responses.

Quick Start

Use the Next.js data-fetching skill to set up a sample app demonstrating server components data fetching, parallel and sequential requests, streaming with Suspense, API route handlers, and client-side fetching with SWR or TanStack Query.

Frequently Asked Questions about nextjs-data-fetching

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

FAQPage Schema
How do I fetch data in Next.js server components?▼

Next.js server components fetch data directly using async/await with built-in request caching. This approach eliminates client-side boilerplate and manages parallel or sequential requests efficiently while enforcing error handling.

What is the best way to stream data fetching with Suspense in Next.js?▼

Streaming data fetching with Suspense in Next.js progressively renders UI as data arrives. Wrapping data-fetching server components in Suspense boundaries improves user experience by displaying fallback content during asynchronous loads.

How do I handle data fetching and caching with SWR or TanStack Query in Next.js?▼

Client-side data fetching with SWR or TanStack Query handles dynamic UI updates in Next.js client components. This integrates with route handlers and server components to manage cache invalidation and type-safe API responses.

Does Next.js support static generation and revalidation for data fetching?▼

Next.js supports static generation using generateStaticParams and Incremental Static Regeneration. These strategies revalidate cached data at runtime, ensuring updated content without full rebuilds while maintaining optimal performance.

How do I manage errors and validate API responses in Next.js route handlers?▼

Next.js route handlers manage errors and validate API responses using consistent error boundaries and type-safe checks. This enforces best practices for data fetching by catching failures and returning typed, predictable outputs.