Skip to content

Commit

Permalink
added global this in scroll to top
Browse files Browse the repository at this point in the history
  • Loading branch information
ShivaBhattacharjee committed Aug 26, 2023
1 parent b48c55b commit b1a1ff5
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/components/shared/ScrollToTop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 && (
Expand Down

0 comments on commit b1a1ff5

Please sign in to comment.