useUrlSearchParams
Reads and updates window.location.search as reactive URLSearchParams synchronized with browser history.
Loading preview...
The useUrlSearchParams hook reads window.location.search via useSyncExternalStore and returns a [searchParams, setSearchParams] tuple that updates the URL using history.pushState or history.replaceState while notifying all subscribed components.
Installation
Usage
Examples
Updating Query Parameters with an Object or Functional Updater
Pass a plain object (where null or undefined removes a parameter) or an updater function that mutates a cloned URLSearchParams instance.
Pushing vs. Replacing History Entries
By default, updates use replaceState so rapid filter changes do not clutter browser history; pass { history: "push" } when you want the Back button to undo the change.
API Reference
UseUrlSearchParamsOptions
Configuration options for browser history mode and initial SSR search params.
Property
Specification
historyMode?union
History API update mode (
'replace' or 'push', default: 'replace').Full Signature
initialValue?union
Fallback query parameters when
window.location.search is empty or during SSR.Full Signature