2021-01-27 08:09:28 +00:00
|
|
|
import { useEffect, useRef } from "react";
|
2020-12-15 11:08:14 +00:00
|
|
|
import { useLocation } from "react-router-dom";
|
|
|
|
|
|
|
|
export default function ScrollToTop() {
|
|
|
|
const { pathname } = useLocation();
|
2021-01-27 08:09:28 +00:00
|
|
|
const scrollRef = useRef();
|
2020-12-15 11:08:14 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
2021-01-27 08:09:28 +00:00
|
|
|
scrollRef.current = document.querySelector(
|
2020-12-28 13:21:59 +00:00
|
|
|
"#customScrollBar > .scroll-body"
|
|
|
|
);
|
2021-01-27 08:09:28 +00:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
scrollRef.current && scrollRef.current.scrollTo(0, 0);
|
2020-12-15 11:08:14 +00:00
|
|
|
}, [pathname]);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|