Skip to content

Commit b882963

Browse files
authored
fix: scroll to top only when pathname changes (#4180)
1 parent 62550a4 commit b882963

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/pages/App.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import TopLevelModals from 'components/TopLevelModals'
66
import ApeModeQueryParamReader from 'hooks/useApeModeQueryParamReader'
77
import { lazy, Suspense } from 'react'
88
import { useEffect } from 'react'
9-
import { Redirect, Route, Switch, useHistory, useLocation } from 'react-router-dom'
9+
import { Redirect, Route, Switch, useLocation } from 'react-router-dom'
1010
import styled from 'styled-components/macro'
1111

1212
import { useAnalyticsReporter } from '../components/analytics'
@@ -80,20 +80,15 @@ function getCurrentPageFromLocation(locationPathname: string): PageName | undefi
8080
}
8181

8282
export default function App() {
83-
const history = useHistory()
8483
const location = useLocation()
84+
const { pathname } = location
8585
const currentPage = getCurrentPageFromLocation(location.pathname)
8686
useAnalyticsReporter()
8787
initializeAnalytics()
8888

8989
useEffect(() => {
90-
const unlisten = history.listen(() => {
91-
window.scrollTo(0, 0)
92-
})
93-
return () => {
94-
unlisten()
95-
}
96-
}, [history])
90+
window.scrollTo(0, 0)
91+
}, [pathname])
9792

9893
return (
9994
<ErrorBoundary>

0 commit comments

Comments
 (0)