我正在尝试从API中获取一些数据,并将其其中一个数组存储在状态内并在其中访问它!但是当我尝试使用上述状态值时,我没有得到定义。componentWillMount()
这是我的代码:
componentWillMount() {
this._fetchData()
************************************
alert(this.state.openSellOffers)
************************************
}
_fetchData = async () => {
let openSellOffersRes = await fetchOpenSellOffers()
for (let sellOffer of openSellOffersRes.orders) {
let sellObj = {
_id: sellOffer._id,
currencyValue: sellOffer.currencyValue,
unitPrice: sellOffer.unitPrice,
totalPrice: sellOffer.totalPrice,
type: 'sell'
}
this.setState({
openSellOffers: [...this.state.openSellOffers, sellObj]
})
}
}
constructor(props) {
super(props)
this.state = {
IRRBalance: 0,
BTCBalance: 0,
openBuyOffers: [],
openSellOffers: [],
closedBuyOffers: [],
closedSellOffers: []
}
}
如您所见,我用于显示状态值。这就是我得到的未定义点,而不是API响应的确切值。alert()
我该如何解决?
宝慕林4294392
桃花长相依
随时随地看视频慕课网APP
相关分类