Skip to content

Commit

Permalink
fix: fix issue with SSR
Browse files Browse the repository at this point in the history
  • Loading branch information
tauqeernasir committed Jan 9, 2020
1 parent b3f6589 commit 00348f7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/scrollbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ export function scrollbar() {
scrollX: 0
})

const isSSR: boolean = typeof window === 'undefined'

// cache last horizontal and vertical scroll positions
let lastScrollX = window.scrollX
let lastScrollY = window.scrollY
let lastScrollX = isSSR ? 0 : window.scrollX
let lastScrollY = isSSR ? 0 : window.scrollY

const handler = () => {
const newScrollY = window.scrollY
Expand Down Expand Up @@ -61,7 +63,7 @@ export function scrollbar() {
}

useEffect(() => {
if (typeof window !== 'undefined') {
if (!isSSR) {
window.addEventListener('scroll', handler)
return () => {
window.removeEventListener('scroll', handler)
Expand Down

0 comments on commit 00348f7

Please sign in to comment.