react solidity event memory leak


react solidity event memory leak



I am getting solidity events from componentdidmount with the following code:


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);
}
});



However, sometimes I am getting this error:



warning.js:33 Warning: Can't call setState (or forceUpdate) on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
in privateData (created by App)



Looks like I need to stop listening for solidity events in componentwillunmount. Does anyone know how to do that?









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

How to set up datasource with Spring for HikariCP?

PHP contact form sending but not receiving emails