Registry / web-framework / react-infinite-scroll-component

react-infinite-scroll-component

JSON →
library7.1.0jsnpmunverified

`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-component
INSTALL
IMPORT
SIG · REACT-INFINITE-SCR
R
react-infinite-scroll-component
web-frameworkjavascriptv7.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

InfiniteScroll
import InfiniteScroll from 'react-infinite-scroll-component';
import { InfiniteScroll } from 'react-infinite-scroll-component';
The `InfiniteScroll` component is a default export for ESM/TypeScript environments.
InfiniteScroll
const InfiniteScroll = require('react-infinite-scroll-component');
const { InfiniteScroll } = require('react-infinite-scroll-component');
For CommonJS environments, `InfiniteScroll` is also a default export.
InfiniteScrollProps
import type { InfiniteScrollProps } from 'react-infinite-scroll-component';
import { InfiniteScrollProps } from 'react-infinite-scroll-component';
TypeScript users can import type definitions using `import type` for clarity and better tree-shaking.

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.

import React, { useState } from 'react'; import InfiniteScroll from 'react-infinite-scroll-component'; interface Item { id: number; content: string; } const style = { padding: 15, borderBottom: '1px solid #eee', minHeight: 50, }; const App: React.FC = () => { const [items, setItems] = useState<Item[]>( Array.from({ length: 20 }, (_, i) => ({ id: i, content: `Initial Item #${i}` })) ); const [hasMore, setHasMore] = useState(true); const fetchMoreData = () => { if (items.length >= 100) { setHasMore(false); return; } // Simulate an API call setTimeout(() => { setItems((prevItems) => [ ...prevItems, ...Array.from({ length: 20 }, (_, i) => ({ id: prevItems.length + i, content: `Fetched Item #${prevItems.length + i}`, })), ]); }, 1500); }; const refreshData = () => { // Simulate re-fetching initial data for pull-to-refresh return new Promise<void>((resolve) => { setTimeout(() => { setItems(Array.from({ length: 20 }, (_, i) => ({ id: i, content: `Refreshed Item #${i}` }))); setHasMore(true); resolve(); }, 1000); }); }; return ( <div> <h1 style={{ textAlign: 'center' }}>Infinite Scroll Demo</h1> <div id="scrollableDiv" style={{ height: 400, overflow: 'auto', margin: '20px auto', border: '1px solid #ccc', width: '80%', }} > <InfiniteScroll dataLength={items.length} next={fetchMoreData} hasMore={hasMore} loader={<h4>Loading...</h4>} endMessage={ <p style={{ textAlign: 'center', padding: '10px' }}> <b>Yay! You have seen it all</b> </p> } refreshFunction={refreshData} pullDownToRefresh pullDownToRefreshThreshold={50} pullDownToRefreshContent={ <h3 style={{ textAlign: 'center', margin: 0, padding: '10px' }}>&#8595; Pull down to refresh</h3> } releaseToRefreshContent={ <h3 style={{ textAlign: 'center', margin: 0, padding: '10px' }}>&#8593; Release to refresh</h3> } scrollableTarget="scrollableDiv" > {items.map((item) => ( <div key={item.id} style={style}> {item.content} </div> ))} </InfiniteScroll> </div> </div> ); }; export default App;
Debug
Known issues
breakingVersion 7.0.0 introduced a breaking change requiring React 17.0.0 or newer. It also leverages the new JSX transform, meaning 'import React' boilerplate is no longer needed.
fix
Upgrade your React and ReactDOM peer dependencies to version 17.0.0 or higher. Ensure your build configuration supports the new JSX transform.
affects: >=7.0.0
breakingVersion 7.0.0 raised the minimum Node.js requirement to 18.18.0.
fix
Ensure your Node.js environment is version 18.18.0 or newer.
affects: >=7.0.0
breakingStarting with v7.1.0, the core scroll-triggering mechanism changed from a throttled scroll event listener to an `IntersectionObserver`. This improves performance by running off the main thread and removed `throttle-debounce` as a dependency. The `onScroll` callback now receives *every* scroll event without internal throttling, which might alter behavior for code relying on the previously throttled events.
fix
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.
affects: >=7.1.0
gotchaThe `scrollableTarget` prop now accepts a direct `HTMLElement` reference in addition to a string ID. While an improvement, developers should be aware of this expanded type signature for consistency.
fix
You can now pass a `useRef` value or a direct DOM element to `scrollableTarget`, e.g., `scrollableTarget={myRef.current}` instead of just `scrollableTarget="myDivId"`.
affects: >=7.1.0
gotchaPrior to v7.0.1, installing the package with React 18 or 19 could lead to peer dependency resolution errors (`ERESOLVE`) due to strict peer dependency declarations.
fix
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.
affects: <7.0.1
gotchaThe `dataLength` prop is crucial for correct functionality. It must represent the current total number of items rendered in the scrollable list. If it's not updated correctly as new items are loaded, the `next` function may not be triggered.
fix
Always ensure `dataLength` accurately reflects the `length` of your `items` array or similar data source that holds your currently rendered content.
affects: >=5.0.0
Errors
Common errors & fixes
npm ERR! ERESOLVE unable to resolve dependency tree
Attempting to install `react-infinite-scroll-component` versions older than 7.0.1 with React 18 or 19 due to strict peer dependency requirements.
fix
Upgrade `react-infinite-scroll-component` to version `^7.0.1` or newer. For example: `npm install react-infinite-scroll-component@latest`.
ReferenceError: React is not defined
This error occurs in React 17+ projects that still include `import React from 'react';` at the top of JSX files, or when using `react-infinite-scroll-component@<7.0.0` with React 17+ configured for the new JSX transform without explicit `import React`.
fix
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.
The 'next' prop function is not being called, or is called unexpectedly.
This usually indicates an issue with `dataLength` not being updated, `hasMore` being `false`, or incorrect `scrollableTarget` configuration (especially with `IntersectionObserver` in v7.1.0+).
fix
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.
Upgrade
Version history
7.1.0latest on npm
Audit
Dependencies
reactrequiredPeer dependency for React components.
react-domrequiredPeer dependency for rendering React components.
Agent activity
4 hits · last 30 days
node
4
Resources
react-infinite-scroll-component — npm install react-infinite-scroll-component · libregistry