Total Complexity | 4 |
Complexity/F | 2 |
Lines of Code | 35 |
Function Count | 2 |
Duplicated Lines | 0 |
Ratio | 0 % |
Coverage | 15.38% |
Changes | 0 |
1 | import React from 'react'; |
||
2 | import { withRouter } from 'react-router-dom'; |
||
3 | 4 | import PropTypes from 'prop-types'; |
|
4 | |||
5 | export class ScrollToTopComponent extends React.Component { |
||
6 | static propTypes = { |
||
7 | location: PropTypes.object, |
||
8 | window: PropTypes.shape({ |
||
9 | scrollTo: PropTypes.func, |
||
10 | }), |
||
11 | children: PropTypes.node, |
||
12 | }; |
||
13 | static defaultProps = { |
||
14 | window, |
||
15 | }; |
||
16 | |||
17 | componentDidUpdate(prevProps) { |
||
18 | const { location, window } = this.props; |
||
19 | |||
20 | 2 | if (location !== prevProps.location) { |
|
21 | window.scrollTo(0, 0); |
||
22 | } |
||
23 | } |
||
24 | |||
25 | render() { |
||
26 | return this.props.children; |
||
27 | } |
||
28 | } |
||
29 | |||
30 | const ScrollToTop = withRouter(ScrollToTopComponent); |
||
31 | |||
32 | export default ScrollToTop; |
||
33 |