Checkbox Inputs

PHOTO EMBED

Mon Apr 25 2022 09:32:06 GMT+0000 (UTC)

Saved by @nimaSm #input

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)
      });
    }
  };
content_copyCOPY

get checkbox values with onChange event