Answer the question
In order to leave comments, you need to log in
Why is the scroll event not firing?
There is this component:
class App extends React.Component {
constructor() {
super();
window.onscroll = function() {
console.log(1);
}
}
componentDidMount() {
window.onscroll = function() {
console.log(1);
}
}
render() {
window.onscroll = function() {
console.log(1);
}
}
}
Answer the question
In order to leave comments, you need to log in
Apparently, because the page does not have the ability to scroll. All content is placed in the height of the window.
If so, then for such cases use the mousewheel event. For cross-browser handling of this event, if the same scroll speed in different browsers is important, you need to use an adapter, like normalize-wheel
try like this
componentDidMount() {
window.addEventListener('scroll', this.handleScroll);
}
componentWillUnmount() {
window.removeEventListener('scroll', this.handleScroll);
}
handleScroll = () => {
alert("scroll");
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question