I am having problems trying to run a function when the page is at the very bottom. I am trying to grab more data from my database when the page is at the very bottom.
My code structure looks something like this
constructor(){
super();
this.state = {
render_count: 1,
}
this.getFeed.bind(this);
}
componentDidMount(){
this.getFeed();
window.addEventListener('scroll', function() {
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
console.log("you're at the bottom of the page");
this.setState({render_count: this.state.render_count+1});
this.getFeed();
}
});
}
getFeed(){//get node.js data}
It seems like this.state is null or some reason. Im getting an error "Cannot read property 'render_count' of undefined" Its also not reading this.getFeed either().
Thanks for all the help!