使用 useFormik 处理复选框
handle checkbox with useFormik
如何使用 useFormik
挂钩 ` ?
我试过了但没用
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>
)
根据documentation maybe you should change your code to something like this
如何使用 useFormik
挂钩 ` ?
我试过了但没用
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>
)
根据documentation maybe you should change your code to something like this