From f61cfc09b0566b60471ead8401a4531552982f84 Mon Sep 17 00:00:00 2001 From: "Tanner Collin (aider)" Date: Mon, 7 Jul 2025 18:15:25 +0000 Subject: [PATCH] refactor: Convert ScrollToTop to functional component with hooks --- webclient/src/ScrollToTop.js | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/webclient/src/ScrollToTop.js b/webclient/src/ScrollToTop.js index 267da92..2bf6867 100644 --- a/webclient/src/ScrollToTop.js +++ b/webclient/src/ScrollToTop.js @@ -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; - } + return null; } -export default withRouter(ScrollToTop); +export default ScrollToTop;