DocSpace-buildtools/packages/asc-web-common/components/Layout/ScrollToTop.js

20 lines
442 B
JavaScript
Raw Normal View History

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