react-intersection-observer

React hooks and a component for tracking when elements enter or leave the viewport.

Library
npm
v11.0.1
5,536stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
84/100Excellent
Development Activity88
Maintenance92
Community56
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
91/100Excellent
Architecture88
Code Quality92
Innovation90
Learning Curve95

react-intersection-observer wraps the browser’s native Intersection Observer API in idiomatic React primitives — the useInView hook, the lighter-weight useOnInView callback hook, and the <InView> render-props/wrapper component — so components can react to visibility changes without hand-rolling observer lifecycle management, cleanup, or SSR guards.

Under the hood, observers with matching root/rootMargin/threshold options are shared across instances, keeping memory and observer counts low even when hundreds of elements are being watched at once (image galleries, infinite feeds, animated sections). It ships full TypeScript types, built-in test mocks for Jest and Vitest, IntersectionObserver v2 support, and works across React 17 through 19.

What You Get

  • Hooks API: useInView for React state-driven visibility, useOnInView for a lower-overhead callback-only variant that skips re-renders.
  • An <InView> component supporting both a function-as-children render-props pattern and plain children with an onChange handler.
  • Automatic observer sharing so many watched elements with identical options reuse a single native IntersectionObserver instance.
  • Full TypeScript type definitions plus a test-utils entry point with mockAllIsIntersecting/intersectionMockInstance helpers for Jest and Vitest.
  • Support for IntersectionObserver v2 (trackVisibility, delay) and a configurable fallbackInView for browsers without native support.

Common Use Cases

  • Triggering scroll-based enter/exit animations as sections come into view.
  • Lazy-loading images, iframes, or heavy components only once they’re about to be visible.
  • Recording impression/analytics events the first time an element becomes visible using triggerOnce.
  • Building infinite-scroll pagination by observing a sentinel element at the end of a list.
  • Implementing reveal-on-scroll or sticky-header behavior tied to scroll position.

Under The Hood

Architecture The package is a thin, layered wrapper: a single shared-state module (observe.ts) implements the observer registry (an observerMap keyed by a stringified options id from optionsToId), sitting beneath the consumer-facing primitives — useIntersectionObserverRef (the low-level ref/effect glue), useInView/useOnInView built on top of that ref, and the class-based InView component that calls observe() directly for its render-props/plain-children API. Data flows one way: a DOM ref registers a callback against a shared IntersectionObserver instance, the observer’s entries callback fans out to per-element callback lists, and hooks/InView translate that into React state or a passed onChange. The shared-observer pool is the core abstraction; if the options-to-id hashing or the pool’s cleanup logic broke, every consumer — hooks and component alike — would silently over- or under-observe elements. This is a clean, modular, single-responsibility layering with no framework or dependency-injection machinery, which suits a focused UI primitive.

Tech Stack Written entirely in TypeScript, built with tsup into dual CJS/ESM output plus matching .d.ts/.d.mts type declarations, and validated post-build with arethetypeswrong and publint for package-export correctness, with bundle-size budgets enforced via size-limit. Its only peer dependencies are react and react-dom across a wide version range, with zero runtime dependencies of its own. The repository is a pnpm-workspace plus Turborepo monorepo, linted and formatted with Biome, and ships a separate Storybook and an Astro-based documentation site as sibling workspace packages. Tests run on Vitest, including a real-browser mode for genuine IntersectionObserver behavior rather than a mocked DOM.

Code Quality Test coverage is extensive, spanning unit tests, an SSR-safety test, and real-browser scroll/intersection tests run through a browser-backed Vitest configuration. Types are strict with essentially no use of any outside a couple of explicitly justified escapes for a generic ref type. Naming is consistent throughout and exported functions carry documentation comments with runnable usage examples. Continuous integration runs the full test suite on every change, and pre-commit hooks run linting automatically. The one fallback code path — behavior when the native API is unsupported — is explicit, documented, and opt-in rather than silently swallowed.

API Design The public surface is intentionally small and layered by ergonomics: useInView returns a result destructurable as either an array or an object, letting callers pick whichever style fits their code; useOnInView exists purely to avoid a re-render for callback-only consumers; <InView> covers the non-hook case with both render-props and plain-children modes. Options mirror the native IntersectionObserverInit almost directly, plus a handful of well-justified additions such as triggerOnce, skip, and fallbackInView, keeping the learning curve close to zero for anyone who already knows the native API. Getting started requires no boilerplate beyond assigning a ref, and bundle size is continuously enforced to stay extremely small.

Used by 25 apps in this directory

Java
48%
Apache 2.0

ClearFlask

Product Management · Community

451

Open-source feedback management and roadmap tool that lets product teams collect, prioritize, and respond to user input — with AI-powered summarization and full self-hosting control.

View details
82
Repo Health
73
Technical
62
Dependency
Built with
Java48%
TypeScript47%
Updated 4 days ago
TypeScript
99%
Apache 2.0

Colanode

Knowledge Management · Team Chat · Collaboration

5,097

Local-first, self-hosted workspace that combines real-time chat, Notion-style pages, and structured databases — all synced via CRDTs so you work offline without losing a keystroke.

View details
47
Repo Health
73
Technical
70
Dependency
Built with
TypeScript99%
Updated 5 months ago
TypeScript
84%
Apache 2.0

Continue

Developer Tools · AI Development · AI Code Assistants

35,808

Open-source coding agent for VS Code, JetBrains, and CLI with support for 30+ LLM providers.

View details
81
Repo Health
88
Technical
62
Dependency
Built with
TypeScript84%
Updated yesterday
Go
49%
Other

Cosmos-Server

Security · Authentication

6,146

All-in-one self-hosted home server with SmartShield anti-DDoS, Nebula mesh VPN, automatic HTTPS, and a 250-app marketplace — all secured behind a unified auth layer.

View details
85
Repo Health
59
Technical
64
Dependency
Built with
Go49%
JavaScript48%
Updated 2 days ago
Rust
67%
Other

DefGuard

Security · Networking · Authentication

2,819

Self-hosted secure remote access that unifies WireGuard VPN, identity management, and connection-level MFA in one open-source platform.

View details
84
Repo Health
82
Technical
72
Dependency
Built with
Rust67%
TypeScript31%
Updated 3 days ago
Python
50%
MIT

Docs

File Storage · CMS

16,788

Open-source collaborative knowledge platform with real-time editing, AI writing tools, and full self-hosting control — built by the French and German governments.

View details
88
Repo Health
81
Technical
71
Dependency
Built with
Python50%
TypeScript42%
Updated yesterday
Go
62%
Apache 2.0

Harness Open Source

Developer Tools · Devops · Code Editors

38,251

A unified open source DevOps platform combining Git hosting, CI/CD pipelines, cloud development environments, and artifact registries in a single self-hosted system.

View details
89
Repo Health
79
Technical
64
Dependency
Built with
Go62%
TypeScript34%
Updated 3 days ago
TypeScript
91%
Apache 2.0

Helicone

Monitoring · AI Development · Analytics

6,133

An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.

View details
69
Repo Health
81
Technical
65
Dependency
Built with
TypeScript91%
Updated 1 weeks ago
TypeScript
99%
AGPL 3.0

Karakeep

Bookmarks Archiving

28,871

Self-hosted bookmark manager that captures links, notes, images, and PDFs with AI tagging, full-text search, and automatic archiving.

View details
88
Repo Health
76
Technical
66
Dependency
Built with
TypeScript99%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search