I'm new to react and I don't understand why I'm getting the following error while setting state on componentDidMount. I did a research on similar errors, and I understand that react wants to be fed with a number, not with a promise. However, I'm pretty sure I'm resolving to a number by writing .then(res => res.json().then(data => data)
. So I can't figure out where's the error from.
Uncaught Error: Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead.
in p (created by Info)
in div (created by Info)
in Info
This is the function that I use to fetch a number:
const get_eth = wallet =>
fetch(
`https://api.etherscan.io/api?module=account&action=balance&address=${wallet}&tag=latest`
)
.then(res =>
res.json().then(data => data["result"] / 10 ** 18)
)
.catch(err => console.log(err));
And this is the setState:
componentDidMount() {
this.setState({eth_q: get_eth("0x0975ca9f986eee35f5cbba2d672ad9bc8d2a0844")})
}