Skip to content

Commit

Permalink
fix(scrollbar): fix winodw is undefined issue for server-side rendering
Browse files Browse the repository at this point in the history
Due to no window check, it was throwing an error when SSRing.
  • Loading branch information
tauqeernasir committed Jan 9, 2020
1 parent d4e2bb6 commit b3f6589
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/scrollbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export function scrollbar() {
let lastScrollY = window.scrollY

const handler = () => {
console.log('hanlder function')
const newScrollY = window.scrollY
const newScrollX = window.scrollX
// check if new horizontal position is greater than cached position
Expand Down Expand Up @@ -62,12 +61,13 @@ export function scrollbar() {
}

useEffect(() => {
window.addEventListener('scroll', handler)

return () => {
window.removeEventListener('scroll', handler)
if (typeof window !== 'undefined') {
window.addEventListener('scroll', handler)
return () => {
window.removeEventListener('scroll', handler)
}
}
return undefined
}, [])
console.log('data = ', data)
return data
}

0 comments on commit b3f6589

Please sign in to comment.