0

I am trying to call a method from my smart contract (myMethod) and save the result (result) as a state (this.state.result) in react. However, my state is not being updated to the result. My code is provided below. How can I fix this?

      await this.contractInstance.methods.myMethod().call({from: this.account, gas: 5000000}).then(result => {return this.state.result = result}).catch('That's a RIP');

2 Answers 2

0

Please take a look at the React documentation: https://reactjs.org/docs/state-and-lifecycle.html#do-not-modify-state-directly.

For example, this will not re-render a component:

// Wrong
this.state.comment = 'Hello';

Instead, use setState():

// Correct
this.setState({ comment: 'Hello' });
0

I dont know if this will help but in my case i had an angular project and it didn't update my attribut so i had to create my instance of State in your case inside the function that returns the result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.