Synchronize UI with query state
A filter, sort, or pagination control needs to reflect the current URL query without maintaining a duplicate source of truth.
Next.js 16+ · Class
ReadonlyURLSearchParams is the read-only query-string interface returned by Next.js useSearchParams. It lets Client Components inspect the current URL without directly mutating its search parameters.
ReadonlyURLSearchParams is the read-only URLSearchParams-like value returned by useSearchParams in a Client Component. It exposes methods for inspecting the current URL query string, while URL updates require creating a separate URLSearchParams instance.
const searchParams = useSearchParams()A read-only URLSearchParams interface; in an application that includes the /pages directory, the result can be ReadonlyURLSearchParams | null.
'use client'
import { useSearchParams } from 'next/navigation'
export default function FilterStatus() {
const searchParams = useSearchParams()
const status = searchParams.get('status')
return <p>Filter: {status ?? 'all'}</p>
}Reads the current URL's status query value in a Client Component.
A filter, sort, or pagination control needs to reflect the current URL query without maintaining a duplicate source of truth.
A Client Component displays a query value such as a search term, category, or status.
A component needs to distinguish the first value from all values for a repeated query key.
It is the read-only version of the URLSearchParams interface returned by useSearchParams. It provides query-string reading utilities such as get, while preventing direct mutation of the current URL search parameters.
Follow-up: How would you update a query parameter? Create a new URLSearchParams from the read-only value, change the copy, and then update the URL through an appropriate client-side navigation mechanism.
useSearchParams returns it in Client Components so they can inspect the current URL query string. The value is intended for reading, not for changing the URL directly.
Follow-up: Why is the hook unavailable in Server Components? The documentation says this prevents stale values during partial rendering; server-side query-dependent work should generally use the Page searchParams prop.
The returned interface includes URLSearchParams reading methods, including get for the first value associated with a name. For repeated names, use getAll when all values are required.
Follow-up: What should a migrating Pages and App Router project type for the result? It should handle ReadonlyURLSearchParams | null because compatibility can produce null.
useSearchParamsURLSearchParamssearchParams propusePathnameuseRouter