`react-infinite-scroll-component` is a lightweight (4.15 kB) and efficient React component designed to implement infinite scrolling experiences in web applications. The current stable version is v7.1.0, with an active development cadence indicated by recent major and minor releases. A key differentiator is its transition to an `IntersectionObserver`-based triggering mechanism in v7.1.0, which enhances performance by running off the main thread and eliminating the need for scroll event throttling, leading to zero runtime dependencies. It supports conventional bottom-to-top scrolling, inverse scrolling (top-to-bottom), and a "pull down to refresh" feature. The component can operate on the document body, within a fixed-height container, or target a specific scrollable DOM element via its ID or a direct `HTMLElement` reference, offering flexibility in integration scenarios. It also requires React 17+ and Node.js 18.18.0+ for development.
npm install react-infinite-scroll-componentVerified import paths — ran on the pinned version, not inferred.
Demonstrates a basic infinite scroll setup with data loading, a loading indicator, an end message, and optional pull-down-to-refresh functionality within a defined scrollable container.
Upgrade your React and ReactDOM peer dependencies to version 17.0.0 or higher. Ensure your build configuration supports the new JSX transform.
Ensure your Node.js environment is version 18.18.0 or newer.
Review any custom logic that interacted with scroll event throttling or relied on the `throttle-debounce` library. Adjust `onScroll` handlers if they expect throttled events, as they will now receive all events.
You can now pass a `useRef` value or a direct DOM element to `scrollableTarget`, e.g., `scrollableTarget={myRef.current}` instead of just `scrollableTarget="myDivId"`.Upgrade to `react-infinite-scroll-component@^7.0.1` or newer. If you were using `--legacy-peer-deps` or `--force` as a workaround, you can now remove these flags.
Always ensure `dataLength` accurately reflects the `length` of your `items` array or similar data source that holds your currently rendered content.
Upgrade `react-infinite-scroll-component` to version `^7.0.1` or newer. For example: `npm install react-infinite-scroll-component@latest`.
For `react-infinite-scroll-component@>=7.0.0`, ensure React is version 17+ and your build tool is configured for the new JSX transform (which removes the need for `import React`). If you are below v7, upgrade React and this package.
Verify that `dataLength` correctly reflects the current number of items, `hasMore` is `true` when more data is expected, and `scrollableTarget` (if used) correctly points to the scrollable container. Ensure your `next` function actually updates the state that `dataLength` depends on.