Skip to main content

Overview

The createLoader function creates a type-safe loader for parsing search parameters from various input types. It’s designed for one-off parsing operations in loaders, API routes, server components, and other server-side contexts.

Function Signature

Parameters

ParserMap
required
An object mapping search param keys to their parser configurations. Each parser defines how to parse and serialize values.
CreateLoaderOptions<Parsers>
Optional configuration object.

Return Value

Returns a LoaderFunction with the following signature:

LoaderInput

The loader accepts multiple input types:

LoaderFunctionOptions

boolean
default:false
Whether to use strict parsing. If true, the loader will throw an error if any of the parsers fail to parse their respective values. If false, the loader will return null or their default value for any failed parsers.

Type Definitions

ParserMap

inferParserType

TypeScript automatically infers the return type based on your parsers:

Examples

Basic Usage

With URL Object

With Request Object

With Next.js 15 Async searchParams

Strict Mode

URL Keys Mapping

Loaders Guide

Learn how to use loaders in different frameworks

createSearchParamsCache

Cache search params in server components

Parsers

Learn about available parser types