Gathering detailed insights and metrics for react-visibility-sensor
Gathering detailed insights and metrics for react-visibility-sensor
Gathering detailed insights and metrics for react-visibility-sensor
Gathering detailed insights and metrics for react-visibility-sensor
@types/react-visibility-sensor
TypeScript definitions for react-visibility-sensor
@rooks/use-visibility-sensor
A React Hooks package for visibility-sensor
@futurejj/react-native-visibility-sensor
A React Native wrapper to check whether a component is in the view port to track impressions and clicks
react-visibility-sensor-v2
Sensor component for React that notifies you when it goes in or out of the window viewport forked by joshwnj.
Sensor component for React that notifies you when it goes in or out of the window viewport.
npm install react-visibility-sensor
Typescript
Module System
Node Version
NPM Version
87.6
Supply Chain
95.6
Quality
80.5
Maintenance
100
Vulnerability
100
License
JavaScript (87.68%)
HTML (12.32%)
Total Downloads
71,079,036
Last Day
18,084
Last Week
186,177
Last Month
903,680
Last Year
11,525,653
2,327 Stars
263 Commits
195 Forks
25 Watching
5 Branches
31 Contributors
Minified
Minified + Gzipped
Latest Version
5.1.1
Package Id
react-visibility-sensor@5.1.1
Size
196.61 kB
NPM Version
6.10.1
Node Version
10.15.3
Publised On
25 Jul 2019
Cumulative downloads
Total Downloads
Last day
-57.4%
18,084
Compared to previous day
Last week
-14.5%
186,177
Compared to previous week
Last month
2.2%
903,680
Compared to previous month
Last year
-38.5%
11,525,653
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 3/23 approved changesets -- score normalized to 1
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