fix: header stuck on certain threshold (#130)

On some cases if the scroll happens fast and multiples times, it will
get stuck on a threshold and not call the `handleScroll` again, by
cleaning the timeoutId everytime `handleScroll` gets called we ensure
that it will not get stuck if scrolling happens too fast.

Co-authored-by: J M Rossy <jm.rossy@gmail.com>
pull/132/head
Jason Guo 1 month ago committed by GitHub
parent 767bae2a99
commit ed7eac97e9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      src/utils/useScrollListener.ts

@ -11,6 +11,7 @@ export function useScrollThresholdListener(threshold: number, debounce = 300) {
const handleScroll = () => {
if (isDebouncing) return;
timeoutId.current = null;
if (window.scrollY > threshold && !isAboveThreshold) {
setIsAbove(true);
setIsDebouncing(true);
@ -24,7 +25,6 @@ export function useScrollThresholdListener(threshold: number, debounce = 300) {
if (!timeoutId.current) {
timeoutId.current = setTimeout(() => {
setIsDebouncing(false);
timeoutId.current = null;
handleScroll();
}, debounce);
}

Loading…
Cancel
Save