const [checkedInput, setCheckedInput] = useState({ currentChekcedInput: [] });
const handleCheckboxOnchange = (e) => {
const { value, checked } = e.target;
const { currentChekcedInput } = checkedInput;
// Case 1 : The user checks the box
if (checked) {
setCheckedInput({ currentChekcedInput: [...currentChekcedInput, value] });
}
// Case 2 : The user unchecks the box
else {
setCheckedInput({
currentChekcedInput: currentChekcedInput.filter((e) => e !== value)
});
}
};