react-within-viewport
Advanced tools
Comparing version 1.0.3 to 1.1.0
{ | ||
"name": "react-within-viewport", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "Debounced React high order component to flag when it's container is inside the viewport.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -22,2 +22,4 @@ import React, { Component } from 'react' | ||
wait = 200, | ||
onViewportEnter = () => {}, | ||
onViewportLeave = () => {}, | ||
} = {}) => (BaseComponent) => class extends Component { | ||
@@ -33,3 +35,3 @@ static displayName = wrapDisplayName(BaseComponent, 'withinViewport') | ||
windowHeight: null, | ||
updated: false, | ||
updated: null, | ||
} | ||
@@ -48,2 +50,12 @@ | ||
componentDidUpdate(prevProps, prevState) { | ||
const was = this.inViewport(prevState) | ||
const is = this.inViewport(this.state) | ||
if (prevState.updated === null && is === false) { onViewportLeave() } | ||
if (prevState.updated === null && is === true) { onViewportEnter() } | ||
if (was === true && is === false) { onViewportLeave() } | ||
if (was === false && is === true) { onViewportEnter() } | ||
} | ||
componentWillUnmount() { | ||
@@ -50,0 +62,0 @@ if (window && window.removeEventListener) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28993
433