How to update array state in react native?

前端 未结 4 1848
無奈伤痛
無奈伤痛 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 15:00

    state

    this.state = {
              barcodeArray:['']
            };
    

    update array

    var barcode_text='hi';
     this.setState({ barcodeArray:[...this.state.barcodeArray,barcode_text] })}
    

提交回复
热议问题