react-infinite-scroller官网
github:ES6中React的无限滚动组件

Installation

  1. npm i react-infinite-scroller

How to use

  1. import InfiniteScroll from 'react-infinite-scroller'

Window scroll events

  1. <InfiniteScroll
  2. pageStart={0}
  3. loadMore={loadFunc}
  4. hasMore={true || false}
  5. loader={<div className="loader">Loading ...</div>}
  6. >
  7. {items} // <-- This is the content you want to load
  8. </InfiniteScroll>

DOM scroll events

  1. <div style="height:700px;overflow:auto;">
  2. <InfiniteScroll
  3. pageStart={0}
  4. loadMore={loadFunc}
  5. hasMore={true || false}
  6. loader={<div className="loader">Loading ...</div>}
  7. useWindow={false}
  8. >
  9. {items}
  10. </InfiniteScroll>
  11. </div>

Props

Name Type Default Description
element String 'div' Name of the element that the component should render as.
hasMore Boolean false Whether there are more items to be loaded. Event listeners are removed if false.
initialLoad Boolean true Whether the component should load the first set of items.
loadMore Function A callback when more items are requested by the user.
pageStart Object 0 The number of the first page to load, With the default of 0, the first page is 1.
threshold Number 250 The distance in pixels before the end of the items that will trigger a call to loadMore.
useWindow Boolean true Add scroll listeners to the window, or else, the component’s parentNode.