@bigfishtv/cockpit
Version:
23 lines (19 loc) • 508 B
JavaScript
import { Component } from 'react'
import { withRouter } from 'react-router-dom'
export default class ScrollToTop extends Component {
_scrollToTop() {
;(document.scrollingElement || document.documentElement || document.body).scrollTop = 0
}
componentDidUpdate(prevProps) {
if (
prevProps.location.pathname !== this.props.location.pathname ||
prevProps.location.search !== this.props.location.search
) {
this._scrollToTop()
}
}
render() {
return this.props.children
}
}