Remove Jquery Document Click Listeners Effecting React Element

问题: For a legacy app we are rewriting parts of web app with React piece by piece. Because of this can't remove junks of document listeners completely. There are lots of documen...

问题:

For a legacy app we are rewriting parts of web app with React piece by piece. Because of this can't remove junks of document listeners completely. There are lots of document on click event listeners and this is effecting react components performance.

For example; Material UI Toggle Menu, https://codesandbox.io/s/o9970jm69 Toggling menu is fast and responsive to your clicks in example. But for our web app because of these document event listeners, toggle behavior is not the same as the demo.

Is it possible to remove these document click listeners for React elements?

Or is there a way to get rid of from these listener for React components?


回答1:

Solution #1 for jQuery events

You can use unbind to remove events. If you need know the event name or type, you can see with Chrome Dev Tools

Solution #2 Javascript events

Another method is capture the event and stop the propagation. You can use removeEventListener or set null the property event.

  • 发表于 2018-12-31 00:11
  • 阅读 ( 208 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除