Skip to main content
The Next.js client is optimized for Next.js applications with support for server components, server actions, and Next.js caching features.

Installation

Basic Usage

1

Create a client instance

2

Use in Server Components

3

Use in Client Components

Configuration

The Next.js client extends the Fetch client with Next.js-specific features:

Client Options

HTTP Methods

Server Components

Use the client in React Server Components:

Server Actions

Use the client in Server Actions:

Route Handlers

Use in Next.js API routes:

Authentication

Server-Side Authentication

Client-Side Authentication

Caching Strategies

Leverage Next.js caching with the fetch options:

Force Cache (Default)

No Store (Dynamic)

Revalidate

On-Demand Revalidation

Interceptors

Request Interceptor

Response Interceptor

Error Interceptor

Server-Sent Events

Stream real-time data in client components:

Advanced Examples

Dynamic Client Configuration

Parallel Data Fetching

Request Deduplication

Next.js automatically deduplicates identical fetch requests:

TypeScript Types

Best Practices

Create a single client instance in a shared module to ensure consistent configuration:
Prefer Server Components for initial data loading to reduce client bundle size:
Always check for errors and provide fallbacks:
Use appropriate caching strategies based on data freshness requirements:

Next Steps

Fetch Client

Learn about the underlying Fetch client

Server Components

Use in React Server Components

Caching

Configure caching strategies

Authentication

Set up API authentication