mapping an array in componentDidUpdate: _Error:Actions must be plain objects

China☆狼群 提交于 2021-02-11 13:45:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!