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
strange behavior of history.goBack() #388
Comments
You forgot to include Before: <a href="#" onClick={() => history.goBack()}> After: <a href="#" onClick={(e) => e.preventDefault(), history.goBack()}> |
Thanks your reminder. |
@Pong420 I think what you're seeing is that effects run immediately when props change, but components (and routes) wait to render until the next tick (request animation frame). You can see this if you add some logging for the rendering:
Now your sequence produces:
I'm not sure why we don't also see an extra effect when links are clicked as we see from browser back and forward, but in any case, it's something to be aware of: Effects run when props they depend on change, even when the component is preparing to unmount. |
you are right, thanks |
Thank you very much. onClick={(e) => { e.preventDefault(); props.history.goBack(); }} |
Minimal CodeSandbox Demo
Step to reproduce
/about
browser history back buttonGo Back
Expected console.log
Actual console.log
The text was updated successfully, but these errors were encountered: