ScrollObserver

A small React component and hook that call your function when an element scrolls into view. Put it after a list to load the next rows, or anywhere on a page to run something when the reader gets that far.

Why I came back to it

I published it in 2019 and then left it alone for seven years. By November 2026 it supported React 16 only, had no types, and could throw an error when it unmounted. Code with my name on it should either work or be taken down, so I brought it up to date.

How it works

  • It renders an empty element and watches it with the browser’s IntersectionObserver. When the element scrolls into view, it calls your function.

  • Set loadMore to false when there is nothing left to fetch, and the calls stop.

  • The useScrollObserver hook does the same for an element you render yourself.

  • In a browser without IntersectionObserver it renders and does nothing.

What keeping it current involved

  • Every push runs the tests against React 16, 17, 18 and 19.

  • The source is TypeScript, and the published types are generated from it. The built files are committed, and the checks fail if they don’t match the source.

  • Versions 0.1.0 and 0.2.0 went to npm from a workflow that holds no npm token. npm checks that the run came from this repository.

  • Those two versions added React 17 to 19, types, a hook and new options. Code written for the 2019 version runs unchanged.

What it does in a team

This is the standard I’d ask of any library a team owns, however small: tests against every version it claims to support, a build that can’t drift from its source, and a release that needs no stored secret.

What it reads, writes and sends

  • It reads whether one element is on screen, through IntersectionObserver.

  • It writes nothing and stores nothing.

  • It sends nothing. It has no dependencies of its own, and it calls only the function you give it.

Install

It’s on npm as @thisnamespace/scrollobserver, and works with React 16.8 and later. The README has the options and examples.

Source

Open source under the MIT licence.

Keyboard shortcuts

1
Go to what I care about
2
Go to the route here
3
Go to experience
4
Go to contact
T
Switch between light, dark and system theme
?
Open this list