refactor: Convert ScrollToTop to functional component with hooks

This commit is contained in:
2025-07-07 18:15:25 +00:00
committed by Tanner Collin
parent 366e76e25d
commit f61cfc09b0

View File

@@ -1,14 +1,10 @@
import React from 'react';
import { withRouter } from 'react-router-dom';
import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';
class ScrollToTop extends React.Component {
componentDidUpdate(prevProps) {
//console.log(this.props.location.pathname, prevProps.location.pathname);
if (this.props.location.pathname === prevProps.location.pathname) {
return;
}
function ScrollToTop() {
const { pathname } = useLocation();
useEffect(() => {
if (localStorage.getItem('scrollLock') === 'True') {
localStorage.setItem('scrollLock', 'False');
return;
@@ -16,11 +12,9 @@ class ScrollToTop extends React.Component {
window.scrollTo(0, 0);
document.body.scrollTop = 0;
}
}, [pathname]);
render() {
return null;
}
}
export default withRouter(ScrollToTop);
export default ScrollToTop;