问题
I could quite advanced in code. And now I'm calculating subtotal. I could calculate the subtotal of first element from detail, but my error is in componentDidUpdate.
In componentDidUpdate if I execute this code,
componentDidUpdate(prevProps, detail, index) {
if (this.props.isSubtotal !== prevProps.isSubtotal) {
this.props.dispatch(
//NEED TO MAKE THE FOLLOWING LINE DYNAMIC AND NOT [0]
change('bill', `detail[0].subtotal`, this.props.isSubtotal)
);
}
}
Works with out any problem. But if I execute this code:
componentDidUpdate(prevProps, detail, index) {
if (this.props.isSubtotal !== prevProps.isSubtotal) {
this.props.dispatch(
Object.keys(this.props.detailItem).map((Item,index) =>{
//Is dynamic this line?
change('bill', `detail[${index}].subtotal`, this.props.isSubtotal)
})
);
}
}
I've got this issue: Error: Actions must be plain objects. Use custom middleware for async actions.
The problem is in syntax I'm using inside this.props.dispatch. How would I do mapping an object with dynamic index inside this.props.dispatch. How can I do dynamic index and not [0]?
I need to solve this. I really need help.
来源:https://stackoverflow.com/questions/60244530/mapping-an-array-in-componentdidupdate-erroractions-must-be-plain-objects