mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-02-28 04:36:45 +00:00
Created component to scroll to top
This commit is contained in:
22
src/common/ScrollToTop.js
Normal file
22
src/common/ScrollToTop.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import React from 'react';
|
||||
import { withRouter } from 'react-router-dom'
|
||||
|
||||
export class ScrollToTop extends React.Component {
|
||||
componentDidUpdate(prevProps) {
|
||||
const { location, window } = this.props;
|
||||
|
||||
if (location !== prevProps.location) {
|
||||
window.scrollTo(0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
||||
ScrollToTop.defaultProps = {
|
||||
window
|
||||
};
|
||||
|
||||
export default withRouter(ScrollToTop);
|
||||
Reference in New Issue
Block a user