Skip to main content
This guide will walk you through creating a simple search interface with nuqs. You’ll learn the core concepts while building something practical.
Make sure you’ve completed the Installation steps before continuing.

Basic Usage: Search Input

Let’s create a search component that stores the query in the URL.
1

Create your component

Create a new client component (for Next.js app router, mark it with 'use client'):
components/Search.tsx
The useQueryState hook works just like useState, but syncs with the URL query string!
2

Try it out

Add the component to your page and start typing. Watch the URL update in real-time:
  • Type “react” → URL becomes ?q=react
  • Click “Clear” → URL becomes / (query removed)
  • Refresh the page → Your input persists!
The URL is the source of truth. When you reload the page, the state is restored from the URL automatically.

Adding Type Safety with Parsers

Let’s add pagination with proper number parsing:
1

Import parsers

nuqs provides built-in parsers for common types:
components/Pagination.tsx
Setting page to 1 (the default value) will clear the query from the URL automatically.
2

Benefits of parsers

  • Type safety: page is always a number, never null
  • Validation: Invalid values are rejected and fall back to the default
  • Serialization: Numbers are properly converted to/from URL strings

Managing Multiple Query States

Use useQueryStates to manage related queries together:
Multiple state updates in the same event are automatically batched into a single URL update.

Next Steps

You now know the basics of nuqs! Here’s what to explore next:

Parsers

Learn about all built-in parsers and how to create custom ones

Options

Control history mode, shallow routing, and throttling

Server-Side

Use nuqs with Server Components and server-side rendering

Testing

Learn how to test components that use nuqs

Common Patterns

Debouncing Input

For search inputs, you might want to debounce URL updates:

History Mode

By default, URL updates replace the current history entry. To enable Back button navigation:

Server Updates (Next.js)

By default, updates are client-only (shallow). To trigger server component re-renders:
Setting shallow: false will cause server components to re-render, which can be slower. Only use this when you need server-side updates.

Complete Example

Here’s a complete example combining everything:
app/page.tsx
This creates a URL like: ?search=laptop&page=2&limit=25