I have a class that gets the available funds on the account from the REST API. This number is saved in state.
I need to create a separate state in which I will store the array of all state changes
For example, my state availableFunds is: 86
So I would like, that my availableFundsArray returns: [86]
If my state availableFunds changes the number to eg: 60
So I would like, that my availableFundsArray returns: [86, 60]
class AvailableFunds extends Component {
constructor() {
super();
this.state = {
availableFunds: [],
availableFundsArray: [],
};
}
componentDidMount() {
this.Auth.availableFunds(this.props.id)
.then(res => {
if (res) {
this.setState({
availableFunds: res.reduce(
(accumulator, currentValue) =>
accumulator + currentValue.available_funds,
0,
),
});
}
})
.catch(err => {
console.log(err);
});
}