Closes #103 - Scroll to top on nav
This commit is contained in:
18
frontend/components/ScrollToTop/ScrollToTop.js
Normal file
18
frontend/components/ScrollToTop/ScrollToTop.js
Normal file
@@ -0,0 +1,18 @@
|
||||
// @flow
|
||||
// based on: https://reacttraining.com/react-router/web/guides/scroll-restoration
|
||||
import { Component } from 'react';
|
||||
import { withRouter } from 'react-router';
|
||||
|
||||
class ScrollToTop extends Component {
|
||||
componentDidUpdate(prevProps) {
|
||||
if (this.props.location !== prevProps.location) {
|
||||
window.scrollTo(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
||||
export default withRouter(ScrollToTop);
|
||||
3
frontend/components/ScrollToTop/index.js
Normal file
3
frontend/components/ScrollToTop/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
// @flow
|
||||
import ScrollToTop from './ScrollToTop';
|
||||
export default ScrollToTop;
|
||||
Reference in New Issue
Block a user