How to use push method in reactjs
I want to push my data by using onChange method in reactjs . For example, I have got initial State
state = { checked: [], permission: {}, data: []}; I want to get this object :
permission : {group:["value2","value1"],topGroup:["value2","value1"]} but the problem is that when I click onChange , It will give me one object each time such as
permission : {group:["value2","value1"]}.
If I add second checkbox , it should add data inside permission object, but I can not push my second data in permission objects . permission objects return one property each time . How to resolve this problem ?
onChange = value => checked => {
this.setState({ checked }, () => {
this.setState(prevState => {
Object.assign(prevState.permission, { [value]: this.state.checked });
});
});
};
<CheckboxGroup
options={options}
value={checked}
onChange={this.onChange(this.props.label)}
/>
Here is my codesanbox:codesandbox.io/s/stackoverflow-a-60764570-3..