Skip to main content
If you’re using a framework or routing solution that doesn’t have a built-in nuqs adapter, you can create your own custom adapter using the unstable adapter API.
The custom adapter API is marked as unstable and may change in future versions. Use the unstable_ prefix when importing types and functions.

Prerequisites

Before creating a custom adapter, ensure:
  1. Your framework provides access to URL search parameters
  2. Your framework has a way to programmatically update the URL
  3. You can detect when the URL changes (for synchronization)

Installation

First, install nuqs:

Creating a Custom Adapter

Step 1: Import the Adapter Utilities

Import the necessary types and functions from nuqs/adapters/custom:

Step 2: Define Your Adapter Hook

Create a hook that implements the unstable_AdapterInterface:

Step 3: Create the Adapter Provider

Use unstable_createAdapterProvider to create your adapter component:

Step 4: Use Your Adapter

Wrap your application with your custom adapter:

Complete Example

Here’s a complete example of a custom adapter for a hypothetical router:
my-custom-adapter.tsx

Advanced: Optimistic Updates

For better UX, you can implement optimistic updates using useOptimistic or local state:

Advanced: Rate Limiting

If your router has different rate limiting characteristics, you can specify a rateLimitFactor:

Advanced: Auto Queue Reset

Some routers need automatic queue resets on navigation. Set autoResetQueueOnUpdate:

Interface Reference

unstable_AdapterInterface

unstable_AdapterOptions

unstable_UseAdapterHook

renderQueryString

Utility function to render URLSearchParams as a query string:

Examples from Built-in Adapters

React Router Based Adapter Pattern

Many routers share similar patterns. Here’s a simplified version of how nuqs creates React Router adapters:

Testing Your Custom Adapter

You can use nuqs’s testing adapter as a reference:

Troubleshooting

Type errors with unstable API

The unstable API requires using the unstable_ prefix. Make sure you’re importing correctly:

Infinite re-render loops

Make sure:
  1. Your searchParams are properly memoized
  2. Your updateUrl function is wrapped in useCallback
  3. Dependencies are correctly specified

Search params not syncing

Ensure:
  1. You’re filtering searchParams by watchKeys
  2. Your router’s search params changes trigger re-renders
  3. The updateUrl function correctly updates your router

Contributing Your Adapter

If you create an adapter for a popular framework, consider contributing it to nuqs! Open a pull request on the nuqs GitHub repository.