简体   繁体   English

反应 如何在React componentWillUnmount中取消订阅事件处理程序?

[英]React. How to unsubscribe event handlers in React componentWillUnmount?

How to solve these warnings from ESLint and make right unsubscription of event handlers below on componentWillUnmount in React 16x? 如何解决来自ESLint这些warnings ,并在React 16x的componentWillUnmount上正确unsubscription以下event handlers

Line 137:  Expected an assignment or function call 
           and instead saw an expression  no-unused-expressions
Line 138:  Expected an assignment or function call 
           and instead saw an expression  no-unused-expressions

When try to unsubscribe from event listeners in React components: 当尝试退订React组件中的事件侦听器时:

componentWillUnmount() {
    this.handleClick === null;
    this.handleSubmit === null;
};

The inline event is never added to the dom, it only lives in React world. 内联事件从未添加到dom中,它仅存在于React世界中。 So there's nothing to actually unsubscribe from.. you can ignore the eslint rule in eslintrc.json by adding the following rule "no-unused-expressions": 0, 因此,实际上没有什么要退订的。通过添加以下规则"no-unused-expressions": 0,您可以忽略eslintrc.json中的eslint规则"no-unused-expressions": 0,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM