Revert ScrollToTop component back to class-based
This commit is contained in:
@@ -1,10 +1,14 @@
|
|||||||
import { useEffect } from 'react';
|
import React from 'react';
|
||||||
import { useLocation } from 'react-router-dom';
|
import { withRouter } from 'react-router-dom';
|
||||||
|
|
||||||
function ScrollToTop() {
|
class ScrollToTop extends React.Component {
|
||||||
const { pathname } = useLocation();
|
componentDidUpdate(prevProps) {
|
||||||
|
//console.log(this.props.location.pathname, prevProps.location.pathname);
|
||||||
|
|
||||||
|
if (this.props.location.pathname === prevProps.location.pathname) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (localStorage.getItem('scrollLock') === 'True') {
|
if (localStorage.getItem('scrollLock') === 'True') {
|
||||||
localStorage.setItem('scrollLock', 'False');
|
localStorage.setItem('scrollLock', 'False');
|
||||||
return;
|
return;
|
||||||
@@ -12,9 +16,11 @@ function ScrollToTop() {
|
|||||||
|
|
||||||
window.scrollTo(0, 0);
|
window.scrollTo(0, 0);
|
||||||
document.body.scrollTop = 0;
|
document.body.scrollTop = 0;
|
||||||
}, [pathname]);
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ScrollToTop;
|
render() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default withRouter(ScrollToTop);
|
||||||
|
|||||||
Reference in New Issue
Block a user