Skip to main content

useSearchParams

Returns a tuple of the current URL’s URLSearchParams and a function to update them. Setting the search params causes a navigation.

Signature

Parameters

URLSearchParamsInit
Optional default search params. This will not change the URL on the first render.Can be:
  • A search param string (e.g., "?tab=1")
  • A shorthand object (e.g., { tab: "1" })
  • An object with array values (e.g., { brand: ["nike", "reebok"] })
  • An array of tuples (e.g., [["tab", "1"]])
  • A URLSearchParams object

Returns

URLSearchParams
The current search params as a URLSearchParams object. This is a stable reference that won’t change between renders.
SetURLSearchParams
A function to update the search params and navigate to the new URL.
URLSearchParamsInit | function
The new search params or a function that receives the current params and returns new params.
NavigateOptions
Optional navigation options like replace, state, preventScrollReset, etc.

Usage

Basic usage

Set search params

Multiple ways to set search params:

Function callback

Update search params based on current values:
The function callback version does not support React’s setState queueing logic. Multiple calls in the same tick will not build on the prior value.
Pass navigation options as the second argument:

Read search params

Default search params

Provide default values that won’t change the URL initially:

Form filters

Tab navigation

Preserve other params

Clear search params

Important Notes

Stable reference

searchParams is a stable reference, safe to use in useEffect dependencies:

Mutability warning

The searchParams object is mutable. If you change it without calling setSearchParams, values will change between renders but the URL won’t update:

Type Safety

Create a type-safe wrapper: