React Infinite Scroller is a lightweight and flexible React component designed to implement infinite scrolling functionality in web applications. It supports both window-based and DOM-element-based scrolling, making it versatile for various layouts. The package is known for not requiring explicit item heights and includes support for 'chat history' or reverse mode scrolling. Currently at version 1.2.6, it demonstrates active maintenance with recent updates for React 18 compatibility. This component provides a simple alternative to more feature-rich (and often heavier) scroll libraries, offering a minimal footprint (approximately 2.2KB minified and gzipped) while being unit-tested and widely adopted in production environments.
npm install react-infinite-scrollerVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to implement infinite scrolling within a specific DOM element using `getScrollParent` to define the scrollable container and simulates loading more items from an API.
Ensure your custom loader component has a unique `key` prop, e.g., `<div className="loader" key={0}>Loading ...</div>`.Ensure your CSS correctly defines the height of the scrollable container and its children. Verify that the height of the container equals the entire height of its items. Consider adding an internal `isLoading` state to your `loadMore` function to prevent overlapping API calls.
Always include `useWindow={false}` when providing a `getScrollParent` function or a `parent` prop for non-window scrolling.Update the `hasMore` prop to `false` in your component's state once all available data has been loaded from your source. This disables further `loadMore` calls and removes event listeners.
This issue was addressed in `v1.2.1`. Ensure you are on a recent version. If using `getScrollParent`, ensure the ref is consistently available before `InfiniteScroll` attempts to access it.
Update to version `1.2.5` or newer to resolve this Chrome-specific vertical scrolling warning.
Upgrade to version `1.2.3` or later to fix the incorrect scrollbar positioning when in reverse scrolling mode.