What could be causing this error in my code?
componentDidMount(){
let container = document.getElementById('body');
container.onscroll = function () {
let height = this.clientHeight;
let scrollHeight = this.scrollHeight;
let scrollTop = this.scrollTop;
if (height + scrollTop === scrollHeight) {
this.setState({ display: 'loader'});
}
}
}
Considering that container is an HTMLElement, there is nowhere it can have a method
setState
so I imagine that the idea of your code is to invoke that method oncomponentDidMount
or rather, on the class that contains it.You can try declaring a reference to
this
outside the context of the functiononscroll
.