From 5846adf2d594705b2adfc24e06dbbcc7a71c8e3b Mon Sep 17 00:00:00 2001 From: alon-s Date: Wed, 20 Mar 2019 17:06:42 +0200 Subject: [PATCH 1/3] added isLoading, to prevent multiple page requests added isLoading property. this is checked before requesting a page, and if the component is currently loading, we don't request another page. solving: https://github.com/CassetteRocks/react-infinite-scroller/issues/143# --- src/InfiniteScroll.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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) { From 69bc8611bc7f51b0f36455ef88b6a86558450399 Mon Sep 17 00:00:00 2001 From: alon-s Date: Wed, 20 Mar 2019 17:09:05 +0200 Subject: [PATCH 2/3] updated README to include isLoading --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b33eb11..b092baf 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 */ }` }| From 15f2a007161c720c35353e119795ceb8023d15dd Mon Sep 17 00:00:00 2001 From: alon-s Date: Wed, 20 Mar 2019 17:09:59 +0200 Subject: [PATCH 3/3] text fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b092baf..2820925 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ You can define a custom `parentNode` element to base the scroll calulations on. |:---- |:---- |:---- |:----| | `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| +| `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 */ }` }|