handle checkbox with useFormik

Viewed 1412

How can I use useFormik hook with ` ?

I tried this but not working

const formik = useFormik({
    initialValues: {
      healthBackground: [],
    },
    onSubmit: (values) => alert(JSON.stringify(values)),
 });
 
 
 return (
 <formik>
 <input type="checkbox" {...formik.getFieldProps("healthBackground")} value="test1" />
 <input type="checkbox" {...formik.getFieldProps("healthBackground")} value="test2" />
 </formik>
 )

1 Answers

According to the documentation maybe you should change your code to something like this

Related