perf: Move to passive scroll listeners where supported

This commit is contained in:
Tom Moor
2022-02-10 19:29:25 -08:00
parent af6c5a1f45
commit 25fd8466e0
4 changed files with 36 additions and 20 deletions

View File

@@ -10,6 +10,7 @@ import Fade from "~/components/Fade";
import Flex from "~/components/Flex";
import useMobile from "~/hooks/useMobile";
import useStores from "~/hooks/useStores";
import { supportsPassiveListener } from "~/utils/browser";
type Props = {
breadcrumb?: React.ReactNode;
@@ -33,7 +34,11 @@ function Header({ breadcrumb, title, actions, hasSidebar }: Props) {
);
React.useEffect(() => {
window.addEventListener("scroll", handleScroll);
window.addEventListener(
"scroll",
handleScroll,
supportsPassiveListener ? { passive: true } : false
);
return () => window.removeEventListener("scroll", handleScroll);
}, [handleScroll]);