Skip to main content
useSearchParams is a Client Component hook that returns a read-only version of the URLSearchParams interface for the current URL query string.
app/dashboard/search-bar.tsx

Parameters

useSearchParams takes no parameters.

Returns

A read-only URLSearchParams instance.
string | null
Returns the first value of the named parameter.
string[]
Returns all values for the named parameter.
boolean
Returns true if the parameter exists.
IterableIterator<string>
Returns an iterator of all parameter names.
IterableIterator<string>
Returns an iterator of all parameter values.
IterableIterator<[string, string]>
Returns an iterator of all [name, value] pairs.
string
Returns the query string as a string (without the leading ?).

Good to know

  • useSearchParams is a Client Component hook and is not supported in Server Components, to prevent stale values during partial rendering.
  • In Server Component pages, read the searchParams prop instead.
  • Layouts do not receive searchParams because they are not re-rendered on navigation.
  • If your app has a /pages directory, useSearchParams may return null on initial render for pages that don’t use getServerSideProps.

Behavior

Prerendering and Suspense

If a route is prerendered, calling useSearchParams causes the Client Component tree up to the closest Suspense boundary to be client-side rendered. Wrap the component in <Suspense> to allow the rest of the page to prerender normally:
app/dashboard/page.tsx
During a production build, a static page that calls useSearchParams from a Client Component must be wrapped in a Suspense boundary, or the build will fail with a Missing Suspense boundary error.

Dynamic rendering

If the route is dynamically rendered (e.g. via the connection function), useSearchParams is available on the server during the initial render:
app/dashboard/page.tsx

Examples

Updating search params

Use useRouter or <Link> to set new search params:
app/example-client-component.tsx

Version history