showing results for - "scoll to top on each route react"
Lia
16 Apr 2017
1import { useEffect } from "react";
2import { useLocation } from "react-router-dom";
3
4export default function ScrollToTop() {
5  const { pathname } = useLocation();
6
7  useEffect(() => {
8    window.scrollTo(0, 0);
9  }, [pathname]);
10
11  return null;
12}
13
14
15function App() {
16  return (
17    <Router>
18      <ScrollToTop />
19      <App />
20    </Router>
21  );
22}
23