How to update Array of objects in React js using state

前端 未结 3 945
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-25 22:16

I want to update value of one object only but updating value of one Object, Updates the value for all objects.

let default = {
    name: \'\',
    age: \'\'
}
th         


        
3条回答
  •  囚心锁ツ
    2021-01-25 23:16

    There is an easy and safe way to achieve that through the following:

    this.setState({
      values: [ newObject, ...this.state.values],
    });
    

    this will create an instance of the state and change the value of an existing object with new object.

提交回复
热议问题