0

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

4
  • Basically you want all checkboxes to be unchecked on load ? Commented Mar 21, 2020 at 16:50
  • yes , when I select checkbox , it will be add Commented Mar 21, 2020 at 18:42
  • @Dreamweaver can you give me the solution for this stackoverflow.com/questions/60829455/… Commented Mar 24, 2020 at 11:55
  • Did you try removing const permission = { group: ["can_view", "can_update", "Orange"], topGroup: ["can_view", "can_update", "Orange"] }; const permission = { group: [], topGroup: [] }; to Commented Mar 25, 2020 at 17:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.