【发布时间】:2019-06-27 07:45:59
【问题描述】:
尝试在异步函数中设置数组的状态,并在异步函数中访问它可以正常工作。但是当我尝试在异步函数之外访问它时,它只解析第一层,意思是 bookDetails[0],而解析 bookDetails[0][0] 时会给出错误“cannot-read-property-0-of-undefined "
getAll = async () => {
const { contract } = this.state;
const response = await contract.methods.getBooks().call();
this.setState({ bookDetails: response});
console.log("books: ",this.state.bookDetails[0][0]);
};
//OUTPUT=> books: nanme
//console.log outside the async function gives error
【问题讨论】:
标签: arrays reactjs mapping solidity