Skip to main content
improved formatting
Source Link
rozsazoltan
  • 19.5k
  • 8
  • 54
  • 158

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})
            })
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 })
})

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})
            })

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 })
})
Source Link

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})
            })