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) }); } };
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter