How to update array state in react native?

前端 未结 4 1858
無奈伤痛
無奈伤痛 2020-12-05 13:56

I am trying to update only one element in an array state but i am not sure of how to do it.

State

constructor(props) {
    super(pro         


        
4条回答
  •  不知归路
    2020-12-05 14:40

    I am trying to push value in an array state and set value like this and define state array and push value by map function.

     this.state = {
            createJob: [],
            totalAmount:Number=0
        }
    
    
     your_API_JSON_Array.map((_) => {
                    this.setState({totalAmount:this.state.totalAmount += _.your_API_JSON.price})
                    this.state.createJob.push({ id: _._id, price: _.your_API_JSON.price })
                    return this.setState({createJob: this.state.createJob})
                })
    

提交回复
热议问题