From 6a1b52e8d9f857786ce1aea812aa1302c6ba1360 Mon Sep 17 00:00:00 2001 From: nemanjam Date: Sun, 4 Aug 2024 12:43:05 +0200 Subject: [PATCH] reduce observer debounce time --- src/components/react/ScrollToTop.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/components/react/ScrollToTop.tsx b/src/components/react/ScrollToTop.tsx index 5579da1..8e2dff4 100644 --- a/src/components/react/ScrollToTop.tsx +++ b/src/components/react/ScrollToTop.tsx @@ -51,12 +51,13 @@ const ScrollToTop: React.FC = ({ 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);