
Product
Introducing Data Exports
Export Socket alert data to your own cloud storage in JSON, CSV, or Parquet, with flexible snapshot or incremental delivery.
react-intersection-observer-hook
Advanced tools
This is a small React hooks package to use [Insersection Observer](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) declaratively. By using these hooks, you can easily track if a component is visible or not, create lazy loading
This is a small React hooks package to use Insersection Observer declaratively. By using these hooks, you can easily track if a component is visible or not, create lazy loading images, trigger animations on entering or leaving the screen etc.
This package is written in TypeScript (all thanks to TSDX). So, you can use it in your TypeScript projects too.
Live demo is here.
You can check the browser compatibility from here.
If you want to support the browsers those are not supporting it natively, you can use this polyfill.
npm install react-intersection-observer-hook
Here is a simple code to use the hook. Just pass the ref callback to the component that you want to track its visibility. You can find a more complete code in the example folder.
import React, { useEffect } from 'react';
import { useIntersectionObserver } from 'react-intersection-observer-hook';
// ...
function Example() {
const [ref, { entry }] = useIntersectionObserver();
const isVisible = entry && entry.isIntersecting;
useEffect(() => {
console.log(`The component is ${isVisible ? "visible" : "not visible"}.`)
},[isVisible])
return (
<SomeComponentToTrack ref={ref} />
);
};
or if you just want to track visibility, you can use useTrackVisibility hook like this;
import React, { useEffect } from 'react';
import { useTrackVisibility } from 'react-intersection-observer-hook';
// ...
function Example() {
const [ref, { isVisible }] = useTrackVisibility();
useEffect(() => {
console.log(`The component is ${isVisible ? "visible" : "not visible"}.`)
},[isVisible])
return (
<SomeComponentToTrack ref={ref} />
);
};
Both useIntersectionObserver and useTrackVisibility gets the same props. And those are;
FAQs
React hook to use IntersectionObserver declaratively.
The npm package react-intersection-observer-hook receives a total of 154,699 weekly downloads. As such, react-intersection-observer-hook popularity was classified as popular.
We found that react-intersection-observer-hook demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Export Socket alert data to your own cloud storage in JSON, CSV, or Parquet, with flexible snapshot or incremental delivery.

Research
/Security News
Bitwarden CLI 2026.4.0 was compromised in the Checkmarx supply chain campaign after attackers abused a GitHub Action in Bitwarden’s CI/CD pipeline.

Research
/Security News
Docker and Socket have uncovered malicious Checkmarx KICS images and suspicious code extension releases in a broader supply chain compromise.