Gathering detailed insights and metrics for react-visibility-sensor-v2
Gathering detailed insights and metrics for react-visibility-sensor-v2
Gathering detailed insights and metrics for react-visibility-sensor-v2
Gathering detailed insights and metrics for react-visibility-sensor-v2
npm install react-visibility-sensor-v2
Typescript
Module System
Node Version
NPM Version
59.2
Supply Chain
94.7
Quality
74.8
Maintenance
100
Vulnerability
100
License
JavaScript (87.98%)
HTML (12.02%)
Total Downloads
45,020
Last Day
24
Last Week
109
Last Month
559
Last Year
7,868
6 Stars
266 Commits
2 Forks
1 Watching
6 Branches
1 Contributors
Latest Version
1.0.0
Package Id
react-visibility-sensor-v2@1.0.0
Unpacked Size
75.38 kB
Size
18.65 kB
File Count
21
NPM Version
6.14.4
Node Version
10.19.0
Cumulative downloads
Total Downloads
Last day
-17.2%
24
Compared to previous day
Last week
9%
109
Compared to previous week
Last month
12%
559
Compared to previous month
Last year
-42.4%
7,868
Compared to previous year
1
Sensor component for React that notifies you when it goes in or out of the window viewport.
Sponsored by X-Team
npm install react-visibility-sensor
Useful if you want to use with bower, or in a plain old <script>
tag.
In this case, make sure that React
and ReactDOM
are already loaded and globally accessible.
Take a look at the umd example to see this in action
View an example on codesandbox
Or if you'd like to try building an example yourself locally, here's another:
To run the example locally:
npm run build-example
example/index.html
in a browserGeneral usage goes something like:
1const VisibilitySensor = require('react-visibility-sensor'); 2 3function onChange (isVisible) { 4 console.log('Element is now %s', isVisible ? 'visible' : 'hidden'); 5} 6 7function MyComponent (props) { 8 return ( 9 <VisibilitySensor onChange={onChange}> 10 <div>...content goes here...</div> 11 </VisibilitySensor> 12 ); 13}
You can also pass a child function, which can be convenient if you don't need to store the visibility anywhere:
1function MyComponent (props) { 2 return ( 3 <VisibilitySensor> 4 {({isVisible}) => 5 <div>I am {isVisible ? 'visible' : 'invisible'}</div> 6 } 7 </VisibilitySensor> 8 ); 9}
onChange
: callback for whenever the element changes from being within the window viewport or not. Function is called with 1 argument (isVisible: boolean)
active
: (default true
) boolean flag for enabling / disabling the sensor. When active !== true
the sensor will not fire the onChange
callback.partialVisibility
: (default false
) consider element visible if only part of it is visible. Also possible values are - 'top', 'right', 'bottom', 'left' - in case it's needed to detect when one of these become visible explicitly.offset
: (default {}
) with offset you can define amount of px from one side when the visibility should already change. So in example setting offset={{top:10}}
means that the visibility changes hidden when there is less than 10px to top of the viewport. Offset works along with partialVisibility
minTopValue
: (default 0
) consider element visible if only part of it is visible and a minimum amount of pixels could be set, so if at least 100px are in viewport, we mark element as visible.intervalCheck
: (default true
) when this is true, it gives you the possibility to check if the element is in view even if it wasn't because of a user scrollintervalDelay
: (default 100
) integer, number of milliseconds between checking the element's position in relation the the window viewport. Making this number too low will have a negative impact on performance.scrollCheck
: (default: false
) by making this true, the scroll listener is enabled.scrollDelay
: (default: 250
) is the debounce rate at which the check is triggered. Ex: 250ms after the user stopped scrolling.scrollThrottle
: (default: -1
) by specifying a value > -1, you are enabling throttle instead of the delay to trigger checks on scroll event. Throttle supercedes delay.resizeCheck
: (default: false
) by making this true, the resize listener is enabled. Resize listener only listens to the window.resizeDelay
: (default: 250
) is the debounce rate at which the check is triggered. Ex: 250ms after the user stopped resizing.resizeThrottle
: (default: -1
) by specifying a value > -1, you are enabling throttle instead of the delay to trigger checks on resize event. Throttle supercedes delay.containment
: (optional) element to use as a viewport when checking visibility. Default behaviour is to use the browser window as viewport.delayedCall
: (default false
) if is set to true, wont execute on page load ( prevents react apps triggering elements as visible before styles are loaded )children
: can be a React element or a function. If you provide a function, it will be called with 1 argument {isVisible: ?boolean, visibilityRect: Object}
It's possible to use both intervalCheck
and scrollCheck
together. This means you can detect most visibility changes quickly with scrollCheck
, and an intervalCheck
with a higher intervalDelay
will act as a fallback for other visibility events, such as resize of a container.
Special thanks to contributors
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/29 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
75 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More