0👍
This might help
this.setState({data: {
...this.state.data,
datasets: [
{
label: this.state.data.datasets[0].label,
data: response.data.rates.AUD,
}
],
});
0👍
I believe the problem is that you are trying to update a value for a property inside an object and you have to do it for the whole data
property:
this.setState({data: {
...this.state.data,
datasets: [
{
label: this.state.data.datasets[0].label,
data: response.data.rates.AUD,
}
],
});
I don’t actually think this code I wrote is correct because I don’t understand the structure of your data, but the idea is that you have to update the whole data
state all together, keeping old data you want to keep and updating new data. You can’t update directly a property in an array in an object. You can update separately first level properties though. Check this: https://itnext.io/react-setstate-usage-and-gotchas-ac10b4e03d60
Source:stackexchange.com