Skip to content

Commit 751306d

Browse files
committed
Fix #518 setSearchParams with a setter docs.
1 parent 6d15d62 commit 751306d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ Refer to [Server-Side Rendering](#server-side-rendering-support-ssr) for more in
361361

362362
### `useSearchParams`: search parameters
363363

364-
Allow you to get and set any search parameters. The first returned value is a `URLSearchParams` object and the second returned value is a setter that accepts a `URLSearchParams` object with options.
364+
Returns a `URLSearchParams` object and a setter function to update search parameters. The setter accepts either a value (object, URLSearchParams, string[][], etc.) or a **callback function** that receives the current params and must return the new params.
365365

366366
```jsx
367367
import { useSearchParams } from 'wouter';
@@ -374,6 +374,7 @@ const id = searchParams.get('id');
374374
// modify a specific search parameter
375375
setSearchParams((prev) => {
376376
prev.set('tab', 'settings');
377+
return prev;
377378
});
378379

379380
// override all search parameters
@@ -387,6 +388,7 @@ setSearchParams({
387388
setSearchParams(
388389
(prev) => {
389390
prev.set('order', 'desc');
391+
return prev;
390392
},
391393
{
392394
replace: true,
@@ -397,6 +399,7 @@ setSearchParams(
397399
setSearchParams(
398400
(prev) => {
399401
prev.set('foo', 'bar');
402+
return prev;
400403
},
401404
{
402405
state: 'hello',

0 commit comments

Comments
 (0)