Why is the state not updating?(为什么状态没有更新?)
I have checked that i receive data from the api in the correct form.(我已经检查过我是否以正确的形式从api接收了数据。) I can print the result if i change it instead of trying to add it to a new array and put it in the state.(如果可以更改结果,则可以打印结果,而不是尝试将其添加到新数组并将其置于状态。) I have also checked that this exists in the scope and as I understand it should work since I am using an arrow function.(我还检查了该范围是否存在,并且据我所知它应该可以正常工作,因为我正在使用箭头功能。) I still receive an empty array after the map function.(map函数之后,我仍然收到一个空数组。) What am I missing?(我想念什么?)class CurrencyForm extends React.Component {
state = {
currencies: [],
}
componentDidMount(){
this.fetchCurrencies();
}
fetchCurrencies = async () => {
const response = await axios.get('some address')
response.data.map(currency =>
this.setState({currencies: [...this.state.currencies,currency.id]}
))
}
ask by daniel translate from so