Skip to content

Navigation resets query state #893

Answered by franky47
comertcimen asked this question in Q&A
Discussion options

You must be logged in to vote

If I use useSearchParams (like code below) instead of nuqs, there is no problem.

Yeah that's what I thought. React Router core isn't really reactive on (shallow) URL updates, and so neither is useSearchParams, which only updates once the navigation has ended. Nuqs needs to have this shallow update as it's the default behaviour (and we expose useOptimisticSearchParams to get the same reactive values nuqs uses internally). But that's the issue here: nuqs reacts to URL changes too quickly (as it should if the URL is supposed to be the source of truth, React Router is lagging behind here).

One trick I can think of is to cache the current search state (in a useRef), update it along the nuqs …

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@comertcimen
Comment options

@franky47
Comment options

@comertcimen
Comment options

@franky47
Comment options

Answer selected by comertcimen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
adapters/react-router Uses the React Router adapter
2 participants