I'm using infinite-scroll on my project. The problem is that when I scroll to top of the window, next function will be called and a request will be sent for fetching new data. While it should call next when I scroll to bottom of the list.
Here's the use case of InfiniteScroll:
<InfiniteScroll dataLength={notificationList.length}
next={this.fetchMoreData}
hasMore={this.state.hasMore}
loader={ <div className={'text-center'}>{Utils.i18n('loadingList', true)}</div>}> {notificationList.length > 0 && notificationList.map((item, index) => { return ( <div key={item.id} name={"scroll-to-element-" + item.id} className={"notification-wrap"}>
<div className={"row"}>
<div className={"col-auto"}>
<h4 className={"title"}> {item.title} </h4>
</div>
<div className={"col-auto mr-auto"}>
<span className={"date"}> {item.createdAt} </span>
</div>
</div>
<div className={"description"}>
<blockquote> {item.description} </blockquote>
</div>
</div> ); })}
</InfiniteScroll>
{notificationList.length === 0 && !notificationListLoading&&
<div className={"text-center my-4"}> {Utils.i18n('noData', true)} </div> }
and fetchMoreData:
fetchMoreData = () => {
if (this.props.notificationSettingReducer.notificationsList) {
if (this.state.page < this.props.notificationSettingReducer.notificationsList.totalPages) {
this.setState({
page: this.state.page + 1
}, () => {
this.getNotification();
});
}
if (this.state.page === this.props.notificationSettingReducer.notificationsList.totalPages) {
this.setState({hasMore: false});
}
}
};
It calls next function on both bottom and top. How can I stop InfiniteScroll from calling next and fetching new data when scroll to top or window.scrollY == 0?