In your handleChange
function, you should change like below:
handleChange = (event, formKey) => {
const { name, checked } = event.target;
// Changed line
const updatedCheckedItems = name === 'All ages' ? { [name]: checked } : { ...this.state.checkedItems, [name]: checked };
this.setState(
{
checkedItems: updatedCheckedItems
},
() => console.log(this.state.checkedItems)
);
};
If the checkbox name is All ages
you should remove all the others, if not, just add one more property on the state object as usual.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…