How do I setState for nested object?

后端 未结 5 644
鱼传尺愫
鱼传尺愫 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 20:55

    let newAccess = Object.assign({}, this.state.access);
    newAccess.hospital_id = 1;
    this.setState({access: newAccess});

提交回复
热议问题