Skip to main content

Overview

The createSearchParamsCache function creates a cache interface for accessing search parameters in deeply nested server components. It uses React’s cache function to ensure parsed values are available throughout the server component tree for a single request.
The cache only works in server components. For client components, use useQueryState or useQueryStates hooks.

Function Signature

Parameters

ParserMap
required
An object mapping search param keys to their parser configurations.
object
Optional configuration object.

Return Value

Returns a CacheInterface with the following methods:

parse()

Parses the incoming search params and stores them in the cache for the current request.
SearchParams | Promise<SearchParams>
required
The searchParams prop from your page component. In Next.js 15+, this may be a Promise.
LoaderFunctionOptions
You must call parse() in your page component before accessing values with get() or all() in nested components.

get()

Retrieves a single cached search param value by key.
keyof Parsers
required
The key of the search param to retrieve.

all()

Retrieves all cached search param values as an object.
Returns an object containing all parsed search param values:

Type Definitions

ParserMap

inferParserType

TypeScript automatically infers the return type based on your parsers:

Examples

Basic Usage

Next.js 15 Async searchParams

Strict Mode

URL Keys Mapping

Using all()

Cache Lifecycle

The cache is scoped to a single page render using React’s cache function:
  • Created when the page component renders
  • Shared across all server components in the tree for that request
  • Cleared after the request completes
  • Isolated between different requests (no cross-request pollution)

Error Handling

The cache will throw an error if you try to access values before calling parse():
The cache will also throw if you call parse() multiple times with different inputs in the same request:
If parse() is called multiple times with the same input (e.g., in both generateMetadata and the page component), the cached result is safely returned.

Cache Guide

Learn how to use the cache in server components

createLoader

One-off parsing with createLoader

Parsers

Learn about available parser types