Gathering detailed insights and metrics for react-intersection-observer-hook
Gathering detailed insights and metrics for react-intersection-observer-hook
Gathering detailed insights and metrics for react-intersection-observer-hook
Gathering detailed insights and metrics for react-intersection-observer-hook
@react-hook/intersection-observer
A React hook for the IntersectionObserver API that uses a polyfill when the native API is not available
react-hook-intersection-observer
A simple React Hook that uses the Intersection Observer API
react-hook-inview
React Hook for detecting when an element is in the viewport
react-cool-inview
React hook to monitor an element enters or leaves the viewport (or another element).
React hook to use IntersectionObserver declaratively.
npm install react-intersection-observer-hook
Typescript
Module System
Node Version
NPM Version
93.4
Supply Chain
93.1
Quality
81
Maintenance
100
Vulnerability
100
License
TypeScript (73.27%)
JavaScript (26.41%)
CSS (0.32%)
Total Downloads
13,394,317
Last Day
5,280
Last Week
118,570
Last Month
505,524
Last Year
5,504,491
MIT License
76 Stars
59 Commits
6 Forks
1 Watchers
1 Branches
1 Contributors
Updated on May 31, 2025
Minified
Minified + Gzipped
Latest Version
4.0.0
Package Id
react-intersection-observer-hook@4.0.0
Unpacked Size
20.49 kB
Size
5.43 kB
File Count
7
NPM Version
10.9.2
Node Version
22.15.0
Published on
May 03, 2025
Cumulative downloads
Total Downloads
Last Day
18.8%
5,280
Compared to previous day
Last Week
-8.4%
118,570
Compared to previous week
Last Month
5.1%
505,524
Compared to previous month
Last Year
44.9%
5,504,491
Compared to previous year
This is a easy to use React hook package for using Insersection Observer declaratively. By using this hook, you can easily track if a component is visible or not, create lazy loading images, trigger animations on entering or leaving the viewport, implement infinite scroll etc.
Live demo is here.
This package relies on Intersection Observer API. Browser compatibility can be seen in here.
If you want to support the browsers those are not supporting it natively, you can use a polyfill.
For React v19, it is recommended to use versions after v4
, since it uses cleanup functions for refs.
For older versions of React, you can stick with v3
until you migrate to React 19.
1npm install react-intersection-observer-hook
1import React, { useEffect } from 'react'; 2import { useIntersectionObserver } from 'react-intersection-observer-hook'; 3// ... 4 5function Example() { 6 // `useIntersectionObserver` returns a tuple. 7 // We need to give this `ref` callback to the node we want to observe. 8 // The second item, `entry` is the response of the `IntersectionObserver` instance. 9 const [ref, { entry }] = useIntersectionObserver(); 10 const isVisible = entry && entry.isIntersecting; 11 12 return ( 13 <div> 14 <p>Component is {isVisible ? 'visible' : 'not visible'}.</p> 15 <SomeComponentToTrack ref={ref} /> 16 </div> 17 ); 18}
If you have a scrollable container, you can set a root
like this:
1import React, { useEffect } from 'react'; 2import { useIntersectionObserver } from 'react-intersection-observer-hook'; 3// ... 4 5function Example() { 6 const [ref, { entry, rootRef }] = useIntersectionObserver(); 7 const isVisible = entry && entry.isIntersecting; 8 9 return ( 10 <div> 11 <p>Component is {isVisible ? 'visible' : 'not visible'}.</p> 12 <ScrollableContainer 13 // We use `rootRef` callback to set the root node. 14 ref={rootRef} 15 > 16 <SomeComponentToTrack ref={ref} /> 17 </ScrollableContainer> 18 </div> 19 ); 20}
If you just want to track visibility, you can also use useTrackVisibility
hook. It mostly has the same API as useIntersectionObserver
hook.
1import React, { useEffect } from 'react';
2import { useTrackVisibility } from 'react-intersection-observer-hook';
3// ...
4
5function Example() {
6 // `useTrackVisibility` also returns a tuple like `useIntersectionObserver`.
7 // First item is the same `ref` callback to set the node to observe.
8 // Second item is an object that we can use to decide if a node is visible.
9 // `entry`: Same object which is returned by `useIntersectionObserver`.
10 // `rootRef`: Same ref callback which is returned by `useIntersectionObserver`.
11 // `isVisible`: Becomes `true`/`false` based on the response of `IntersectionObserver`.
12 const [ref, { entry, rootRef, isVisible }] = useTrackVisibility({
13 // In addition to the `IntersectionObserver` arguments, you can use `once` flag
14 // to watch the visibility of an element once, so `isVisible` stays `true` after the element is visible for the first time.
15 // once: true,
16 });
17
18 return (
19 <div>
20 <p>Component is {isVisible ? 'visible' : 'not visible'}.</p>
21 <SomeComponentToTrack ref={ref} />
22 </div>
23 );
24}
You can find more usage examples in the demo
app in this repository.
useIntersectionObserver
rootMargin
: Indicates the margin value around the root element. Default value is 0
for all directions (top, right, bottom and left).threshold
: Threshold value (or values) to trigger the observer.For more info, you can check here and here.
Gets the same arguments as useIntersectionObserver
. In addition:
once
: When set true
, isVibisle
stays as true
after the element is visible for the first time. Default false
.Thanks goes to these wonderful people (emoji key):
KimSeonghyeon 💻 | ||||||
|
This project follows the all-contributors specification. Contributions of any kind welcome!
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
9 existing vulnerabilities detected
Details
Reason
Found 1/29 approved changesets -- score normalized to 0
Reason
1 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
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
Score
Last Scanned on 2025-06-09
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