The first false notification is ignored and the page says so three times
React implementation of the Intersection Observer API to tell you when an element enters or leaves the viewport.
At a glance
- What is it?
- react-intersection-observer wraps a browser API in three shapes, from a hook that holds state to a callback hook that deliberately does not, and it makes one behavioural choice that a reader will hit on day one: the initial not-visible report never reaches your code. The workspace around it is a small study in how the same three jobs get described twice.
- Who is it for?
- Use this if you need to know when something scrolls into view, because it matches the browser API rather than reinventing it, shares observers so a long list costs one observer rather than fifty, and ships a mock so your tests do not need a browser. Two things to know before you write against it.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 32 days ago.
- What is it written in?
- Mainly TypeScript, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.
Star history
- thebuilder/react-intersection-observer5,541 ★ · +3
| Repository | 2026-09-23 | 2026-11-25 |
|---|---|---|
| thebuilder/react-intersection-observer | 5.5k | 5.5k |
3 Stars in the last 63 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
The initial not-visible report never reaches your code
Every entry point in this package carries the same note, and it is the note you will need. When you attach the observer, the browser immediately reports the element's current state, which for anything below the fold is not visible. That first false report is ignored on purpose, so your handler only runs after a genuine visibility change. Subsequent transitions report both states normally, as the element enters and leaves. The note appears once under the state hook, once under the callback hook, and once under the render-props form. The practical consequence is a piece of behaviour you will only find if you think about it: an element that is off screen when the page loads will not fire a leave event, because there was no enter to leave. If you need to know the initial state, the hook returns it to you as a value, which is the supported way to ask.
Observers with matching options are shared across elements
The performance claim on the page is architectural rather than measured, and it is the reason to prefer this wrapper over a hand-rolled one. An observer created with one set of options is reused by every element watched with the same options, so a list of a thousand items costs one observer rather than a thousand. The practical reading is that the cost of watching many elements is bounded by the number of distinct option sets you use. Everything else in the feature list follows the same philosophy of staying close to the platform: options map straight onto the native initialisation object rather than being translated.
One hook holds state and re-renders, the other holds neither
The two hooks are not variants of each other, and the page is careful to list four differences. The state hook returns a ref, a boolean and the entry, and re-renders the component when the boolean changes. The callback hook holds no state at all, so a visibility change never triggers a render, which is the point of it for impression tracking on a long list. It also hands the callback the entry directly, so there is no lookup for the element the entry belongs to, and its first argument is the current boolean rather than the entry, which deliberately matches the change handler signature of the state hook so the two can be swapped without rewriting the call. The fourth difference is a subtraction: the callback hook accepts every option the state hook does except the three that only make sense when you are holding state.
The simplest component form does not forward refs
The component offers two shapes, and the note attached to the simpler one is the one to read before choosing it. Give it any element and it wraps it, creating the containing element itself, and extra props are passed through to that element, so a class name or a style goes straight to the markup. That is the convenient path when you only want to observe visibility and keep the state in your own component. The limitation is stated plainly: the component does not forward refs, so if you need a ref to the underlying element, for measuring it or focusing it or handing it to another library, the render-props form is the one to use, because its children receive the ref directly. The same note tells you to pick the element type to match the surrounding markup rather than accepting whatever the default is, which is the other half of writing semantic output.
Around one kilobyte gzipped for the hook, one and a half for the component
Two size figures are published, one for the state hook and one for the wrapper component, both gzipped, and they are the kind of number most libraries in this space do not print. The supporting claims are the standard ones: only the parts you import end up in your bundle, the types ship with the package, and there is a mock of the browser API that works with both of the common test runners, which means a visibility test does not need a real viewport. Installation is one command:
npm install react-intersection-observer --saveThere is a link to an editable example on a browser-based playground just above that command. The case for this package over a dozen-line component of your own rests on the shared observers, the published sizes and the mock rather than on any comparison.
The same three jobs are described twice, by a task runner and by hand
The repository root is a workspace with three packages in it: the library itself, a component workshop and a documentation site. Build, lint, type-check and test are wired twice. There are scripts that build, lint, type-check and test, each written out by hand as a filtered sequence, and there are two more that hand the same work to a task runner with a configuration file at the root. The two sets are not identical in shape. The hand-written type check builds the library first and then type-checks all three packages, while development runs the three package servers in parallel and lint runs them one after another.
Six deprecation warnings are silenced rather than fixed
One configuration block in the workspace manifest is worth reading on its own. It lists six packages whose deprecation warnings the build is allowed to ignore, and it accepts any version of each of them, which means the workspace will not fail on a future version of something already deprecated. The list is a minifier plugin, three source-map helpers, and two other small packages, stable and urix, which tells you the bundling pipeline still depends on a plugin that has been superseded and on a cluster of source-map helpers. The rest of the workspace is tighter. The package manager itself is pinned to an exact version with a content hash appended, so a compromised or moved tag cannot change what gets installed, and commits run a lint-staged pass through a git hook, with Biome and fallow both listed as development dependencies.
Editorial conclusion
Use this if you need to know when something scrolls into view, because it matches the browser API rather than reinventing it, shares observers so a long list costs one observer rather than fifty, and ships a mock so your tests do not need a browser. Two things to know before you write against it. The first not-visible report is swallowed on purpose, so a handler that fires on leaving the viewport will not run for an element that started off screen. And the simplest component form does not forward refs, which matters the moment you need to measure or focus the element yourself; the render-props form is the way out.
Frequently asked questions
how to install react intersection observer
One install command from the package registry with the save flag. The package ships its own types, and the page gives size figures for two of its entry points, around 1.15kB gzipped for the state hook and 1.6kB for the wrapper component, plus an editable example on a browser-based playground.
How do I use the Intersection Observer in React?
Three ways. A hook that returns a ref, a visibility boolean and the entry, and which re-renders on change; a callback hook that takes a handler and returns a ref but holds no state, so nothing re-renders; and a component that accepts either a function as its children for render props, or a plain element which it wraps itself, with extra props passed to the wrapping element.
Why does my handler not fire when the element starts off screen?
Because the package ignores the first not-visible notification the browser sends when the observer attaches, so handlers only run after a real visibility change. That note is repeated for all three entry points. Later enter and leave transitions report both states normally, and the initial state is available as a value from the hook.
Can I get a ref to the element from the wrapper component?
Not from the plain-children form, because the component does not forward refs. Its note says to use the render-props form if you need a ref to the HTML element, where the children function receives the ref directly. The note also says to choose the element type to match the surrounding markup and to add a class name so the output stays styled.
What is the difference between an intersection observer and a scroll event?
The readme describes the observer as reporting when an element enters or leaves the viewport, and lists scroll animations, lazy loading, impression tracking and infinite scroll as the uses it is meant for. If you are choosing between the two, the case for this package is the shared observers, the published bundle sizes and the test mock rather than any stated comparison.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/thebuilder-react-intersection-observer)Star history chart for your README
[](https://hysenlabs.com/projects/thebuilder-react-intersection-observer)Was this useful?