Registry / web-framework / react-window-infinite-loader

react-window-infinite-loader

JSON →
library2.0.1jsnpmunverified

react-window-infinite-loader provides utilities for implementing infinite scrolling lists with `react-window`. It is inspired by `react-virtualized`'s `InfiniteLoader` but is specifically designed to work as a lightweight companion for `react-window`'s fixed and variable size lists. The current stable version is 2.0.1, released as of this documentation. The library's release cadence is tied to its maintainer's work on `react-window` and `react-virtualized`, often seeing updates for React compatibility or minor feature enhancements. Key differentiators include its tight integration with `react-window`, offering both a `useInfiniteLoader` hook for functional components and a `InfiniteLoader` component for class-based or render-prop patterns, making it adaptable to various component architectures. It helps manage the loaded state of rows and triggers data loading as users scroll near the end of the list.

npm install react-window-infinite-loader
INSTALL
IMPORT
SIG · REACT-WINDOW-INFIN
R
react-window-infinite-loader
web-frameworkjavascriptv2.0.1
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.

useInfiniteLoader
import { useInfiniteLoader } from 'react-window-infinite-loader'
import useInfiniteLoader from 'react-window-infinite-loader'
This is the recommended hook for functional components. It's a named export, not a default.
InfiniteLoader
import { InfiniteLoader } from 'react-window-infinite-loader'
const InfiniteLoader = require('react-window-infinite-loader')
The `InfiniteLoader` component is a named export. ESM `import` is the primary usage pattern.
InfiniteLoaderProps
import type { InfiniteLoaderProps } from 'react-window-infinite-loader'
Import types explicitly when using TypeScript for better type checking.

This example demonstrates how to use the `useInfiniteLoader` hook with `react-window`'s `FixedSizeList` to implement a basic infinite scrolling list. It simulates fetching data asynchronously and updates the list as new rows are loaded.

import { useInfiniteLoader } from 'react-window-infinite-loader'; import { FixedSizeList } from 'react-window'; import React, { useState, useCallback } from 'react'; const Row = ({ index, style, isLoaded }) => ( <div style={style}> {isLoaded ? `Row ${index}` : `Loading row ${index}...`} </div> ); const ExampleList = ({ itemCount, isRowLoaded, loadMoreRows }) => { const [items, setItems] = useState(Array(itemCount).fill(false)); const infiniteLoaderProps = { isRowLoaded, loadMoreRows, itemCount, threshold: 5, minimumBatchSize: 10 }; const onRowsRendered = useInfiniteLoader(infiniteLoaderProps); return ( <FixedSizeList height={300} itemCount={itemCount} itemSize={50} width={500} onRowsRendered={onRowsRendered} > {({ index, style }) => ( <Row index={index} style={style} isLoaded={isRowLoaded({ index })} /> )} </FixedSizeList> ); }; function App() { const ROW_COUNT = 1000; const isItemLoaded = ({ index }) => index < loadedItems.length; const [loadedItems, setLoadedItems] = useState(Array(50).fill(true)); const loadMore = useCallback(async (startIndex, stopIndex) => { console.log(`Loading rows from ${startIndex} to ${stopIndex}`); // Simulate API call await new Promise(resolve => setTimeout(resolve, 1000)); setLoadedItems(prev => { const newItems = [...prev]; for (let i = startIndex; i <= stopIndex; i++) { if (!newItems[i]) { newItems[i] = true; } } return newItems; }); }, []); return ( <ExampleList itemCount={ROW_COUNT} isRowLoaded={isItemLoaded} loadMoreRows={loadMore} /> ); } export default App;
Debug
Known issues
breakingThe `InfiniteLoader` component underwent significant changes in version 2. The `onItemsRendered` parameter in its child function was renamed to `onRowsRendered`, and the `listRef` parameter was entirely removed. Existing code using the `InfiniteLoader` component from v1 will break if not updated to reflect these parameter changes.
fix
Update the render prop signature for `InfiniteLoader` from `{ onItemsRendered, listRef }` to `{ onRowsRendered }`. Pass the `onRowsRendered` prop to your `react-window` list component.
affects: >=2.0.0
gotchaIt's crucial that the `loadMoreRows` prop passed to `useInfiniteLoader` or `InfiniteLoader` returns a Promise. If it does not return a Promise that resolves when data is loaded, the component will not correctly track the loading state, potentially leading to repeated fetches or a broken infinite scroll experience.
fix
Ensure your `loadMoreRows` function is `async` or explicitly returns a Promise. For example: `async (startIndex, stopIndex) => { await fetchData(startIndex, stopIndex); }` or `(startIndex, stopIndex) => { return new Promise(resolve => fetchData(startIndex, stopIndex).then(resolve)); }`.
affects: >=1.0.0
gotchaIncorrectly managing the `isRowLoaded` state can lead to either rows perpetually showing as loading or `loadMoreRows` being called too frequently or not at all. The `isRowLoaded` function must accurately reflect whether the data for a given `index` is available.
fix
Ensure your `isRowLoaded` function correctly checks the loaded state for the given `index` against your data source. This often involves checking if `index < yourDataSource.length` or if a specific item in your data array at `index` is defined.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'then')
`loadMoreRows` did not return a Promise.
fix
Make sure your `loadMoreRows` function returns a Promise that resolves when data fetching is complete. If using `async/await`, ensure the `async` keyword is present. If using a standard Promise, ensure it is explicitly returned.
React Hook 'useInfiniteLoader' is called in a function that is neither a React function component nor a custom React Hook function.
`useInfiniteLoader` is called outside of a functional React component or another custom hook.
fix
Ensure `useInfiniteLoader` is only called at the top level of a functional React component or within another custom hook that itself adheres to React Hook rules.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
reactrequiredRequired for React component and hook functionality.
react-domrequiredRequired for rendering React components.
react-windowrequiredCore virtualization library this package extends, not a direct dependency but a necessary peer for usage.
Agent activity
4 hits · last 30 days
node
4
Resources
react-window-infinite-loader — npm install react-window-infinite-loader · libregistry