Skip to content

Commit a3b5b95

Browse files
committed
Add note to useSearchParams about setState queueing behavior
1 parent eebcb51 commit a3b5b95

File tree

1 file changed

+8
-1
lines changed
  • packages/react-router/lib/dom

1 file changed

+8
-1
lines changed

packages/react-router/lib/dom/lib.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2151,7 +2151,8 @@ export function useLinkClickHandler<E extends Element = HTMLAnchorElement>(
21512151
* setSearchParams(new URLSearchParams("?tab=1"));
21522152
* ```
21532153
*
2154-
* It also supports a function callback like React's [`setState`](https://react.dev/reference/react/useState#setstate):
2154+
* It also supports a function callback like React's
2155+
* [`setState`](https://react.dev/reference/react/useState#setstate):
21552156
*
21562157
* ```tsx
21572158
* setSearchParams((searchParams) => {
@@ -2160,6 +2161,12 @@ export function useLinkClickHandler<E extends Element = HTMLAnchorElement>(
21602161
* });
21612162
* ```
21622163
*
2164+
* <docs-warning>The function callback version of `setSearchParams` does not support
2165+
* the [queueing](https://react.dev/reference/react/useState#setstate-parameters)
2166+
* logic that React's `setState` implements. Multiple calls to `setSearchParams`
2167+
* in the same tick will not build on the prior value. If you need this behavior,
2168+
* you can use `setState` manually.</docs-warning>
2169+
*
21632170
* ### Notes
21642171
*
21652172
* Note that `searchParams` is a stable reference, so you can reliably use it

0 commit comments

Comments
 (0)