what is the preferred way to mutate a React state?

前端 未结 4 1129

Let\'s say I have a list of plain objects in my this.state.list that I can then use to render a list of children. What then is the right way to insert object in

4条回答
  •  -上瘾入骨i
    2020-12-07 10:22

    Update 2016

    With ES6 you can use:

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

提交回复
热议问题