Skip to main content
useListParams is a hook that synchronizes list page filtering, sorting, and pagination state with URL search parameters. It provides bookmarkable state management and type-safe form binding.

Core Features

URL Sync

Store search params in URLBookmarkable state

Type Safety

Zod schema basedAutomatic type inference

Auto Page Reset

Reset to page 1 on filter changeImproved UX

register Pattern

Easy form component bindingRemove boilerplate

Basic Usage

Import and Initialization

Parameter Explanation:
  • UserListParams: Zod schema (auto-generated)
  • Default value object: Initial values when URL has no values
Why is a Zod schema needed?URL search parameters are strings, so a schema is needed to parse them into numbers or booleans. UserListParams is auto-generated in sonamu.generated.ts and always stays in sync with backend type definitions.

Using listParams

An object containing the current filtering state.
Type:

Changing State with setListParams

Change filter state and update URL.
How it works:
  1. Deep equal comparison between listParams and newParams
  2. If changed, update URL with TanStack Router’s navigate
  3. URL change β†’ useSearch hook re-runs β†’ listParams automatically updated
Important: Always use spread operator
Always use spread operator to preserve existing filter values.

Form Binding with register

The register function automatically provides value and onValueChange to form components.
What register returns:
Why auto page reset?: If a user changes the search keyword on page 3, there may be fewer results and page 3 may not exist. Therefore, all filter changes except page automatically return to page 1.

Real-world Examples

Complete List Page

Adding Custom Filters

When custom filters are added in the backend:
Frontend usage:

URL Sharing and Bookmarking

The biggest advantage of useListParams is that filter state is stored in the URL.
Benefits of bookmarkable state:
  • Users can bookmark frequently used filter combinations
  • Share URL to show colleagues the same view
  • Navigate through filter history with browser back/forward

Options

disableSearchParams

Disable URL synchronization and manage state locally only.
Use cases:
  • List inside a modal (when you don’t want to change URL)
  • Embedded widget (when independent state management is needed)
  • Test environment
Using disableSearchParams: true will disable bookmark and URL sharing functionality.

Type Safety

Compile-time Validation

Auto-completion

When typing register(" in IDE, all available fields are auto-completed.

TanStack Router Integration

useListParams internally uses TanStack Router hooks:
  • useSearch: Read URL search parameters
  • useNavigate: Update URL
Meaning of strict: falseuseSearch({ strict: false }) allows reading search parameters not defined in the current route. This enables flexible handling of dynamically added filters.

Cautions

1. Setting Initial Values

Required fields:
  • num: Items per page
  • page: Current page (starts from 1)

2. Type Assertion for Enum Fields

3. Using register with Custom onChange