Revert ScrollToTop component back to class-based

This commit is contained in:
2025-12-02 17:02:03 +00:00
parent bf3e6bbc28
commit 4c9d5eede1

View File

@@ -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]); }
render() {
return null; return null;
}
} }
export default ScrollToTop; export default withRouter(ScrollToTop);