React Intersection Observer screenshot

React Intersection Observer

Author Avatar Theme by Thebuilder
Updated: 23 May 2025
5326 Stars

React implementation of the Intersection Observer API to tell you when an element enters or leaves the viewport.

Overview:

The react-intersection-observer is a library that provides a React implementation of the Intersection Observer API. This allows users to monitor when an element enters or leaves the viewport. It offers Hooks, render props, and plain children implementations, making it versatile for different use cases.

Features:

  • Hooks or Component API: It provides both Hooks and Component API for monitoring elements easily.
  • Optimized performance: Reuses Intersection Observer instances where possible for improved performance.
  • Matches native API: Intuitive to use and provides an experience similar to the native API.
  • Written in TypeScript: Fits seamlessly into existing TypeScript projects.
  • Ready to test: Mocks the Intersection Observer for easy testing with Jest or Vitest.
  • Tree-shakeable: Allows including only the necessary parts, optimizing bundle size.
  • Tiny bundle: Offers a small bundle size, approximately ~1.15kB for useInView and ~1.6kB for .

Installation:

To install the package, you can use your preferred package manager:

npm install react-intersection-observer

Summary:

The react-intersection-observer library is a powerful tool for monitoring elements in a React application. With features like optimized performance, support for TypeScript, and easy testing capabilities, it provides developers with a reliable solution for handling visibility changes in their components. Whether using Hooks, render props, or plain children implementations, this library offers flexibility and efficiency in monitoring elements entering or leaving the viewport.