反应固态事件内存泄漏

时间:2018-07-03 07:06:07

标签: reactjs events memory-leaks solidity

我正在使用以下代码从componentdidmount中获取固体事件:

      myDataSocks.events.ReceivedPayment({}, async (error, event) => {
        if (!error) {
          const account = event.returnValues.fromAcct;
          const payment = web3.utils.fromWei(event.returnValues.payment);

          console.log('ReceivedPayment: ', account, payment);
          this.notify(`You received ${payment} ether from ${account}`);

          let contractBalance;
          await web3.eth.getBalance(address).then(function(result) {
            contractBalance = web3.utils.fromWei(result);
          });

          this.setState({ contractBalance });

        } else {
          console.log('ReceivedPayment error:', error);
        }
      });

但是,有时我会收到此错误:

warning.js:33警告:无法在已卸载的组件上调用setState(或forceUpdate)。这是空操作,但它表明应用程序中发生内存泄漏。要解决此问题,请在componentWillUnmount方法中取消所有订阅和异步任务。     在privateData(由App创建)中

好像我需要停止在componentwillunmount中监听实体事件。有谁知道该怎么做?

0 个答案:

没有答案