'How to render a variable from a function
So I'm trying to render a constructor variable but when I add the lines that renders it, the whole page goes blank. I don't know if it's that this.balance() is not called there or sm.
I'm new so help is appreciated :)
constructor(props){
super(props)
this.state = {
balance: ""
}
}
balance = async() => {
const web3 = window.web3
const balance = web3.eth.getBalance(this.state.account)
this.setState({balance})
}
render(){
this.balance()
return(
<section id="payments">
Payments
<Nav/>
<p>balance: {this.state.balance}</p>
</section>
)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
