diff --git a/src/hooks/useElementScroll.ts b/src/hooks/useElementScroll.ts index 925a8bba4..fa4156ced 100644 --- a/src/hooks/useElementScroll.ts +++ b/src/hooks/useElementScroll.ts @@ -35,7 +35,11 @@ function useElementScroll(anchor: MutableRefObject): Position { ); anchor.current.addEventListener("scroll", handleScroll); - return () => anchor.current.removeEventListener("scroll", handleScroll); + return () => { + if (!!anchor.current) { + anchor.current.removeEventListener("scroll", handleScroll); + } + }; } }, [anchor.current]);