From bc021ce550f1aedfaabb2e51d95ca0bd8bb211ed Mon Sep 17 00:00:00 2001 From: streamich Date: Sat, 23 Mar 2019 08:40:31 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20cancel=20animation=20fram?= =?UTF-8?q?e=20on=20un-mount=20in=20useWindowScroll()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/useWindowScroll.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/useWindowScroll.ts b/src/useWindowScroll.ts index 4003c7d469..234f119423 100644 --- a/src/useWindowScroll.ts +++ b/src/useWindowScroll.ts @@ -16,7 +16,6 @@ const useWindowScroll = (): State => { useEffect(() => { const handler = () => { cancelAnimationFrame(frame.current) - frame.current = requestAnimationFrame(() => { setState({ x: window.scrollX, @@ -30,7 +29,10 @@ const useWindowScroll = (): State => { passive: true }) - return () => window.removeEventListener('scroll', handler) + return () => { + cancelAnimationFrame(frame.current); + window.removeEventListener('scroll', handler); + }; }, []) return state