diff --git a/src/behaviors/Visibility/Visibility.js b/src/behaviors/Visibility/Visibility.js index 4c1126eee1..547cda644b 100644 --- a/src/behaviors/Visibility/Visibility.js +++ b/src/behaviors/Visibility/Visibility.js @@ -7,6 +7,7 @@ import { getElementType, getUnhandledProps, META, + isBrowser, } from '../../lib' /** @@ -141,7 +142,7 @@ export default class Visibility extends Component { } static defaultProps = { - context: window, + context: isBrowser ? window : null, continuous: false, once: true, } @@ -170,11 +171,15 @@ export default class Visibility extends Component { } componentDidMount() { + if (!isBrowser) return + const { context } = this.props context.addEventListener('scroll', this.handleScroll) } componentWillUnmount() { + if (!isBrowser) return + const { context } = this.props context.removeEventListener('scroll', this.handleScroll) } diff --git a/src/modules/Sticky/Sticky.js b/src/modules/Sticky/Sticky.js index 3b7cd0316c..e8db79619a 100644 --- a/src/modules/Sticky/Sticky.js +++ b/src/modules/Sticky/Sticky.js @@ -7,6 +7,7 @@ import { getElementType, getUnhandledProps, META, + isBrowser, } from '../../lib' /** @@ -74,7 +75,7 @@ export default class Sticky extends Component { static defaultProps = { bottomOffset: 0, offset: 0, - scrollContext: window, + scrollContext: isBrowser ? window : null, } static _meta = { @@ -87,12 +88,16 @@ export default class Sticky extends Component { } componentDidMount() { + if (!isBrowser) return + const { scrollContext } = this.props this.handleUpdate() scrollContext.addEventListener('scroll', this.handleUpdate) } componentWillUnmount() { + if (!isBrowser) return + const { scrollContext } = this.props scrollContext.removeEventListener('scroll', this.handleUpdate) }