pbeshai / use-query-params

React Hook for managing state in URL query parameters with easy serialization.
https://pbeshai.github.io/use-query-params
ISC License
2.16k stars 96 forks source link

Preserve query params on router change #194

Closed donegjookim closed 2 years ago

donegjookim commented 2 years ago

Our application has a use case to preserve query params for next time the user comes back to a page via React Router.

For example,

Expected behavior /pageA?param=7 -> /page/B -> /pageA?param=7

Current behavior /pageA?param=7 -> /page/B -> /pageA

Is there a way to persist the query param state globally?

pbeshai commented 2 years ago

How are they coming back to the page? If using the back button, the push and pushIn (default) update types in setQuery will do that. If they're using a link, you just need to manage that state and include it in your link.

donegjookim commented 2 years ago

The users would may back to the page using links and back button. It'd be nice for the library to support this functionality out of the box as keeping track of all the links would go out of control.

pbeshai commented 2 years ago

It won't be added to this library. You can store the state for links by making your own custom link component that manages it, it's not too bad and you can control how it caches to work how you expect.