Skip to content

Commit

Permalink
reduce observer debounce time
Browse files Browse the repository at this point in the history
  • Loading branch information
nemanjam committed Aug 4, 2024
1 parent 605c7fa commit 6a1b52e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/components/react/ScrollToTop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ const ScrollToTop: React.FC<Props> = ({ children }) => {
});

if (linkRef.current) {
isAtTop || isAtBottom ? hideLink(linkRef) : showLink(linkRef);
if (isAtTop || isAtBottom) hideLink(linkRef);
else showLink(linkRef);
}
};

// bellow 200 or it will break again
const debouncedCallback = debounce(callback, 100);
// bellow 100 or it will break again on fast scroll
const debouncedCallback = debounce(callback, 20);
const intersect = new IntersectionObserver(debouncedCallback);

if (topRef.current) intersect.observe(topRef.current);
Expand Down

0 comments on commit 6a1b52e

Please sign in to comment.