From b1a1ff58c2bf2984bafa9189303cbd5eae40d9ac Mon Sep 17 00:00:00 2001 From: ShivaBhattacharjee Date: Sat, 26 Aug 2023 17:07:38 +0530 Subject: [PATCH] added global this in scroll to top --- src/components/shared/ScrollToTop.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/shared/ScrollToTop.tsx b/src/components/shared/ScrollToTop.tsx index 4e8bcea..d573f86 100644 --- a/src/components/shared/ScrollToTop.tsx +++ b/src/components/shared/ScrollToTop.tsx @@ -21,12 +21,15 @@ const ScrollToTop = () => { } }; - window.addEventListener('scroll', listenToScroll); - return () => { - window.removeEventListener('scroll', listenToScroll); - }; + if (typeof globalThis !== 'undefined') { + globalThis.addEventListener('scroll', listenToScroll); + return () => { + globalThis.removeEventListener('scroll', listenToScroll); + }; + } }, []); + return ( <> {isVisible && (