use-query-params
use-query-params copied to clipboard
fix: notify WindowHistoryAdapter when the page's URL is updated
Fixes the issue rained here: https://github.com/pbeshai/use-query-params/discussions/283
WindowHistoryAdapter is broken because when a component updates a query param in the URL, the lib does not notify the query params consumer to read the new value. As a result, the URL is changed, but the internal react state holds the stale value.
Also, the adapter needs to consider URL changes when someone clicks on the browser's Back and Forward buttons.
PS: My solution was also broken, and finally I ended up with the same idea as @websaid shared in https://github.com/pbeshai/use-query-params/discussions/283#discussioncomment-8171698
This is a PR to add his solution to the repo.
LGTM. We have this in production for a year now and it is working well.
Seems the main thing is just forcing a re-render here by calling setState on adapter, right? will merge since it seems this solution works for window users, i've never actually used the adapter