I am working on React js on one code where I am using select element and onChange event.
handleChange = (event) => {
this.setState({value: event.target.value});
}
render() {
return (
<div>
<label>
List
<select value={this.state.value} onChange={this.handleChange}>
<option value="one">One</option>
<option value="two">Two</option>
</select>
</label>
</div>
)
But I am getting this warning again and again in chrome. "[Violation] Added non-passive event listener to a scroll-blocking 'mousewheel' event. Consider marking event handler as 'passive' to make the page more responsive.". Is there any resolution for it.
Basically, all
scrollandtouchevents expect to be "passive" ifpreventDefault()is not called. But it's not that easy..default-passive-eventsjsut blindly apply passive attribute ignoring the usage ofpreventDefault()and that might cause your script break..passive: falseto all the events will remove the warning, but will not improve the performance. Whats the point then?I was dealing with such issue not a long ago and created a package that overwrites
EventTarget.prototype.addEventListenerand addpassiveoption to all the events that do notpreventDefaultand if browsers supports it.https://www.npmjs.com/package/passive-events-support
This not only removed the warning, but also improved the performance. Make sure to pass only necessary events instead of default. In this case just 'mousewheel':
If you want a modular way, you can find an example in the docs. Make sure to import this script before any other script that causes that warning.