I have div which has onWheel
.
Browser treat onWheel as scroll by default.
However I want to stop mouse browser behaivor in under condition.
However, for now I bumped into Unable to preventDefault inside passive event listener invocation
error. some article says I should use { passive: false }
in addEventListener, but how can I do this in React?
handleWheel(e){
if (e.ctrlKey){
console.log("wheel is called, then want to stop scroll!!");
e.stopPropagation(); //It doesn't stop default scroll behaivor.
e.preventDefault(); //it shows the error Unable to preventDefault inside passive event listener invocation.
}
}
<div onWheel={handleWheel} >
2
Answers
please try like below:
as the error message mentioned:
you have explicit to set the event listener to active by
{ passive: false }