How do I setState for nested object?

后端 未结 5 632
鱼传尺愫
鱼传尺愫 2020-11-29 20:36

For a plugin I\'m using I have to have a state that looks like this:

getInitialState() {
  return {
    invalid: true,
    access: {
      access_code: \'\',         


        
5条回答
  •  一生所求
    2020-11-29 21:09

    I had this same issue too(not the same context) anyways, i did the code below in my own work and it worked perfectly

    this.setState({
      access: {
        ...this.state.access,
        hospital_id: 1,
      },
    });
    

提交回复
热议问题