Replies: 1 comment 1 reply
-
https://stackblitz.com/edit/remix-run-remix-m9ldmb?file=app%2Froutes%2F_index.tsx |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The docs for
setSearchParams
states that it can be called with a function that accepts the previous search params and kinda acts likesetState
1.So my expectation was that, if I returned the previous search params, the page wouldn't reload. But I was taken by surprise: the page reloaded — which is contrary to how setState behaves when you return the previous/old value. I'm not sure how this affects an SPA/react router app, but in a remix app, this causes double page loads.
Here's my usage:
I thought it was an oversight but an example from the docs did
prev.set('key', value)
and returnedprev
.Looking at the source code for
useSearchParams
, in an attempt to push a "fix", the last change was 2 years ago and I've seen no reports on theuseSearchParams
API — which is surprising. Maybe because people haven't noticed or are fine with its design. So I resorted to duplicating the code in my project to insert a check onprev
before making a refresh.My ask is, what do you think about not navigating to the new params when we return the previous one — which mimics how
setState
actually works.Footnotes
https://reactrouter.com/en/main/hooks/use-search-params "Just as React's useState, setSearchParams also supports functional updates..." ↩
Beta Was this translation helpful? Give feedback.
All reactions