Remove listener only if it exists
This commit is contained in:
parent
2d9fc51bfb
commit
928f19c879
1 changed files with 5 additions and 1 deletions
|
@ -35,7 +35,11 @@ function useElementScroll(anchor: MutableRefObject<HTMLElement>): Position {
|
||||||
);
|
);
|
||||||
anchor.current.addEventListener("scroll", handleScroll);
|
anchor.current.addEventListener("scroll", handleScroll);
|
||||||
|
|
||||||
return () => anchor.current.removeEventListener("scroll", handleScroll);
|
return () => {
|
||||||
|
if (!!anchor.current) {
|
||||||
|
anchor.current.removeEventListener("scroll", handleScroll);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}, [anchor.current]);
|
}, [anchor.current]);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue