-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Call transition hooks when query changes for useQueries #2137
Conversation
Thanks for the PR, @schnerd! Would you mind rebasing on current master? The tests should pass now. |
aa935a2
to
6161e21
Compare
@mjackson think we're good to go 👍 |
Call transition hooks when query changes for useQueries
uh onEnter should definitely not be called here. Query params usually indicate the state of the current route/component, does not mean entering a new Route/Page. This leads to undesired behavior such as page scrolling to the top when query param changes. Let's say you are using params/query params as state for the current tab, or a search box half way through the page. Whenever a push/replace state happens the page jumps back up. |
@sikanhe On the other hand you may want |
@th0r but isn't it much harder to manually program preserve scrolling than to scroll to the top? Scroll to the top is just window.scrollTo(0,0). On the other hand, it's much harder to do a one liner for "make sure to save the current position at x, y when query param changes". Correct me if i am wrong |
Perhaps, it should be done by analogy with React's componentWillMount (onRouteEnter) & componentWillUpdate (onRouteChange). |
Fixes #2122
Any time the query params change, onLeave and onEnter hooks will both be called.
If comparing
state.location.query
instead ofstate.location.search
would be more appropriate, let me know and I can adjust the PR–state.location.search
was just easiest since it's a simple string comparison.