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
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.Changing State with setListParams
Change filter state and update URL.- Deep equal comparison between
listParamsandnewParams - If changed, update URL with TanStack Routerβs
navigate - URL change β
useSearchhook re-runs βlistParamsautomatically updated
Form Binding with register
Theregister function automatically provides value and onValueChange to form components.
page automatically return to page 1.
Real-world Examples
Complete List Page
Adding Custom Filters
When custom filters are added in the backend:URL Sharing and Bookmarking
The biggest advantage ofuseListParams is that filter state is stored in the URL.
- 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.- List inside a modal (when you donβt want to change URL)
- Embedded widget (when independent state management is needed)
- Test environment
Type Safety
Compile-time Validation
Auto-completion
When typingregister(" in IDE, all available fields are auto-completed.
TanStack Router Integration
useListParams internally uses TanStack Router hooks:
useSearch: Read URL search parametersuseNavigate: Update URL
Meaning of strict: false
useSearch({ 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
num: Items per pagepage: Current page (starts from 1)
2. Type Assertion for Enum Fields
3. Using register with Custom onChange
Related Documentation
- Using Services - API call methods
- TanStack Query Integration - Caching and refetching
- auto-generated-overview - Auto-generated components
- useSelection - Multi-select management