You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Functional updates to the search params using urlSearchParams don't seem to work in the same way as useState does. When making consecutive functional updates using setState, each time the function is called it receives the most up-to-date value. Ex.
setSearchParams is simply calling navigate under the hood. What that means is the set operation needs to go through a full routing/render cycle until the updated data is made available, even to the function form. You should combine your calls to setSearchParams.
@timdorr thanks for replying. That's fair, but what's the purpose of providing the callback API then? It seems misleading to provide this API if this behavior isn't supported - if we ever need to read params we should only use the first element of useSearchParams()
What version of React Router are you using?
6.24.0
Steps to Reproduce
Functional updates to the search params using
urlSearchParams
don't seem to work in the same way asuseState
does. When making consecutive functional updates usingsetState
, each time the function is called it receives the most up-to-date value. Ex.The difference in behavior is also shown in this stackblitz:
https://stackblitz.com/edit/github-rmemxe?file=src%2FApp.tsx
Expected Behavior
The "search param based count" should increment by 2
Actual Behavior
The "search param based count" only increments by 1
The text was updated successfully, but these errors were encountered: