Cancel scroll watcher timeout

This commit is contained in:
Jackson Harper
2023-03-11 08:27:34 +08:00
parent f811339398
commit c19460eb75

View File

@ -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])
}