this.state = {
page: 1
}
onScroll = () =>{
let elem = document.getElementById("longTable");
let loading = true // this can change depening on if an api call is in progress
if ((elem.offsetHeight + elem.scrollTop) >= elem.offsetHeight - 10 &&!loading ) {
this.setState(prevState => ({ page: prevState.page + 1 }), () =>
console.log("Now You can Scroll")
// this.props.onLoadMore(this.state.page)
)
}else{
// debugger;
console.log("finally--- no more api calls")
}
}
<div
className={"long-table"}
id={"longTable"}
onScroll={this.onScroll}
style={{ width: "-webkit-fill-available" }}
>
</div>;
.long-table {
overflow-y: auto;
height: 600px;
}
This is what i have done, but it keeps making api calls even when i scroll up or down..
How Can i detect scrolling in that div such that scrolling up will not make api calls, but scrolling down will make api call only when a certian height has been reached, i cannot be scolling down and be making api calls all the time..
Any help please