我正在发出两个 api GET 请求,并且我希望更新状态。由于某种原因,它仅使用第一个 GET 请求中的值进行更新。
我尝试使用扩展运算符更新状态并将新值添加到来自 GET 请求的当前状态(类别)。
axios // first get request
.get(
"LINK_TO_API"
)
.then(res => {
this.setState({
...this.state.categories,
categories: res.data.data
});
})
.catch(function(error) {
console.log(error);
});
axios // second get request
.get(
"LINK_TO_API"
)
.then(res => {
this.setState({
...this.state.categories,
categories: res.data.data
});
})
.catch(function(error) {
console.log(error);
});
我目前从第一个 GET 请求中获得 10 个值,并且希望在映射类别时获得总共 20 个值。