From c19460eb759eb91a5f07363a316fca9b96860fee Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Sat, 11 Mar 2023 08:27:34 +0800 Subject: [PATCH] Cancel scroll watcher timeout --- packages/web/lib/hooks/useScrollWatcher.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/web/lib/hooks/useScrollWatcher.tsx b/packages/web/lib/hooks/useScrollWatcher.tsx index 19580ed43..af47493f3 100644 --- a/packages/web/lib/hooks/useScrollWatcher.tsx +++ b/packages/web/lib/hooks/useScrollWatcher.tsx @@ -37,6 +37,11 @@ export function useScrollWatcher(effect: Effect, delay: number): void { } window.addEventListener('scroll', handleScroll) - return () => window.removeEventListener('scroll', handleScroll) + return () => { + if (throttleTimeout.current) { + clearTimeout(throttleTimeout.current) + } + window.removeEventListener('scroll', handleScroll) + } }, [currentOffset, delay, effect]) }