You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Often you will need to scroll to the top of a long page, that when navigated to stays scrolled down. Make sure to wrap it in withRouter to give it access to the Router's props.
import React, { Component } from 'react';
import { withRouter } from 'react-router-dom';
class ScrollTopOnNavigation extends Component {
componentDidUpdate(prevProps) {
if (this.props.location !== prevProps.location) {
window.scrollTo(0, 0);
}
}
render() {
return this.props.children;
}
}
export default withRouter(ScrollTopOnNavigation);
// Then render it at the top of your app, but below the Router: