diff --git a/README.md b/README.md index b33eb11..2820925 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ import InfiniteScroll from 'react-infinite-scroller'; pageStart={0} loadMore={loadFunc} hasMore={true || false} + isLoading={true || false} loader={
Loading ...
} > {items} // <-- This is the content you want to load @@ -48,6 +49,7 @@ import InfiniteScroll from 'react-infinite-scroller'; pageStart={0} loadMore={loadFunc} hasMore={true || false} + isLoading={true || false} loader={
Loading ...
} useWindow={false} > @@ -67,6 +69,7 @@ You can define a custom `parentNode` element to base the scroll calulations on. pageStart={0} loadMore={loadFunc} hasMore={true || false} + isLoading={true || false} loader={
Loading ...
} useWindow={false} getScrollParent={() => this.scrollParentRef} @@ -81,8 +84,9 @@ You can define a custom `parentNode` element to base the scroll calulations on. | Name | Type | Default | Description| |:---- |:---- |:---- |:----| -| `element` | `Component` | `'div'` | Name of the element that the component should render as.| +| `element` | `Component` | `'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`.| +| `isLoading` | `Boolean` | | Whether there is a page being loaded now| | `initialLoad` | `Boolean` | `true` | Whether the component should load the first set of items.| | `isReverse` | `Boolean` | `false` | Whether new items should be loaded when user scrolls to the top of the scrollable area.| | `loadMore`       | `Function`   |           | A callback when more items are requested by the user. Receives a single parameter specifying the page to load e.g. `function handleLoadMore(page) { /* load more items here */ }` }| diff --git a/src/InfiniteScroll.js b/src/InfiniteScroll.js index b08637e..15414d3 100644 --- a/src/InfiniteScroll.js +++ b/src/InfiniteScroll.js @@ -7,6 +7,7 @@ export default class InfiniteScroll extends Component { element: PropTypes.node, hasMore: PropTypes.bool, initialLoad: PropTypes.bool, + isLoading: PropTypes.bool.isRequired, isReverse: PropTypes.bool, loader: PropTypes.node, loadMore: PropTypes.func.isRequired, @@ -216,7 +217,7 @@ export default class InfiniteScroll extends Component { this.beforeScrollHeight = parentNode.scrollHeight; this.beforeScrollTop = parentNode.scrollTop; // Call loadMore after detachScrollListener to allow for non-async loadMore functions - if (typeof this.props.loadMore === 'function') { + if (typeof this.props.loadMore === 'function' && !this.props.isLoading) { this.props.loadMore((this.pageLoaded += 1)); this.loadMore = true; } @@ -249,6 +250,7 @@ export default class InfiniteScroll extends Component { hasMore, initialLoad, isReverse, + isLoading, loader, loadMore, pageStart, @@ -268,7 +270,7 @@ export default class InfiniteScroll extends Component { }; const childrenArray = [children]; - if (hasMore) { + if (isLoading) { if (loader) { isReverse ? childrenArray.unshift(loader) : childrenArray.push(loader); } else if (this.defaultLoader) {