Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added isLoading property #206

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import InfiniteScroll from 'react-infinite-scroller';
pageStart={0}
loadMore={loadFunc}
hasMore={true || false}
isLoading={true || false}
loader={<div className="loader" key={0}>Loading ...</div>}
>
{items} // <-- This is the content you want to load
Expand All @@ -48,6 +49,7 @@ import InfiniteScroll from 'react-infinite-scroller';
pageStart={0}
loadMore={loadFunc}
hasMore={true || false}
isLoading={true || false}
loader={<div className="loader" key={0}>Loading ...</div>}
useWindow={false}
>
Expand All @@ -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={<div className="loader" key={0}>Loading ...</div>}
useWindow={false}
getScrollParent={() => this.scrollParentRef}
Expand All @@ -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 */ }` }|
Expand Down
6 changes: 4 additions & 2 deletions src/InfiniteScroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -249,6 +250,7 @@ export default class InfiniteScroll extends Component {
hasMore,
initialLoad,
isReverse,
isLoading,
loader,
loadMore,
pageStart,
Expand All @@ -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) {
Expand Down