Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-within-viewport

Package Overview
Dependencies
Maintainers
4
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-within-viewport - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

2

package.json
{
"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) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc