Storing an object in state of a React component?

后端 未结 6 1166
野趣味
野趣味 2020-12-07 16:05

Is it possible to store an object in the state of a React component? If yes, then how can we change the value of a key in that object using setState? I think it

6条回答
  •  一个人的身影
    2020-12-07 16:51

    Easier way to do it in one line of code

    this.setState({ object: { ...this.state.object, objectVarToChange: newData } })
    

提交回复
热议问题