Infinitely load content using a React Component. This fork maintains a simple, lightweight infinite scroll package that supports both window and scrollable elements.
npm i react-infinite-scroller
The module supports ES6 imports with jsnext:main and require with main in the package.json.
import InfiniteScroll from 'react-infinite-scroller'
<InfiniteScroll
pageStart={0}
loadMore={loadFunc}
hasMore={true || false}
loader={<div className="loader">Loading ...</div>}>
{items} // <-- This is the content you want to load
</InfiniteScroll> <div style="height:700px;overflow:auto;">
<InfiniteScroll
pageStart={0}
loadMore={loadFunc}
hasMore={true || false}
loader={<div className="loader">Loading ...</div>}
useWindow={false}>
{items}
</InfiniteScroll>
</div>-
pageStart: The page number corresponding to the initialitems, defaults to0which means that for the first loading,loadMorewill be called with1 -
loadMore(pageToLoad): This function is called when the user scrolls down and we need to load items -
hasMore: Boolean stating whether there are more items to be loaded. Event listeners are removed iffalse. -
loader: Loader element to be displayed while loading items - You can useInfiniteScroll.setDefaultLoader(loader);to set a defaut loader for all yourInfiniteScrollcomponents -
threshold: The distance between the bottom of the page and the bottom of the window's viewport that triggers the loading of new items - Defaults to250 -
useWindow: Boolean stating whether to add listeners to the window, or else, the DOMNode