How to remove initial default objects in reactjs

馋奶兔 提交于 2020-04-17 21:31:53

问题


when I click on checkbox my output should be this format

{permission:{group:["1","2"]}}

and also if I click second one my output should be this format

{permission:{group:["1","2"]},topgroup:["1"]}. 

currently , I see two default objects like this by using intital state

{permission:{group:[]},topgroup:[]}.

I don't need to get initial state like this {permission:{group:[]},topgroup:[]}. I just want to add data when user click on checkbox.

how can I remove initial state ?

  UNSAFE_componentWillMount() {
    this.setDefault(false);
  }

  setDefault = fill => {
    const temp = {};
    group.forEach(x => (temp[x] = fill ? groupItems : []));
    this.setState({ permission: temp });
  };

here is my codesanbox : https://codesandbox.io/s/stackoverflow-a-60764570-3982562-v1-um18k

来源:https://stackoverflow.com/questions/60790181/how-to-remove-initial-default-objects-in-reactjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!