Reputation: 388
I am getting API response and once after getting that I am applying some filter and want to assign the result to state variables.
Here is what I am trying to do:
filtered = this.state.result
.filter(value => value.Date == bar.Date)
.reduce((acc, e) => acc.concat(e.FailureDeatils), []);
this.setState({ failureResultValue: filtered });<-- Here I am able to set the filtered to failureResultValue.
Again on this failureResultValue,I am applying filter and able to achieve the result i.e.
failureResultTransactions = this.state.failureResultValue
.filter(data => data.name == pie.name)
.reduce((acc, item) => acc.concat(item.TransactionDetails) , []).map(item => ({ ...item, checked: false }));
console.log(failureResultTransactions );<- It has value
this.setState({ items: failureResultTransactions });<- This is not working
console.log(this.state.items)<- is returning empty
Can anyone figure out where I am going wrong?
Upvotes: 2
Views: 1089
Reputation: 2319
this.setState({ items: failureResultTransactions },()=>
console.log(this.state.items));
You can check like this
Upvotes: 1