NodeJs: Whenever checkbox is checked I wanted them to be added to my VerificationData setter

I need help on how to add data on my array whenever one/or many of them are checked.

const [data, setData] = useState([]);

{
    verifications.map(record => {
        console.log(verifications)
        return(
            <Col xs={12} md={3} mb={3}>
                <Form.Group key={record.id} className="mb-3" controlId={record.verifyName}>
                      <Form.Check value={record.verifyName} label={record.verifyName} />
                  </Form.Group>
            </Col>  

            )
    })
}

Example: • First Name • Last Name • Address

If I checked on first name and address, they will be added to my state setter for data.

Appreciate your help.

Answer

You need to have an onChange event inside the check input and call setData function to set value. Here an example

const [data, setData] = useState([]);

  useEffect(() => {
    console.log(data);
  }, [data]);

  return (
    <div>
      <input
        type="checkbox"
        value="Rahul"
        name="firstName"
        onChange={e => setData([...data, e.target.value])}
      />
    </div>