const {values, handleChange, handleSubmit, errors} = useFormik({
initialValues: {
name: '',
address: '',
latitude: '',
longitude: '',
nit: '',
category: '',
email: '',
},
validationSchema: {formSchema},
validateOnChange: false,
onSubmit: () => console.log(values),
})
En: The error occurs because we are surrounding the validation schema with keys, we must pass it without keys, keep in mind the validateOnchange.
Es: El error ocurre porque estamos rodeando el esquema de validación con llaves, debemos pasarlo sin llaves, tener presente el validateOnchange
const {values, handleChange, handleSubmit, errors} = useFormik({
initialValues: {
name: '',
address: '',
latitude: '',
longitude: '',
nit: '',
category: '',
email: '',
},
validationSchema: {formSchema},
validateOnChange: false,
onSubmit: () => console.log(values),
})
En: The error occurs because we are surrounding the validation schema with keys, we must pass it without keys, keep in mind the validateOnchange.
Es: El error ocurre porque estamos rodeando el esquema de validación con llaves, debemos pasarlo sin llaves, tener presente el validateOnchange
Share Improve this question asked Dec 5, 2022 at 21:15 Alexander Rincón S.Alexander Rincón S. 511 silver badge2 bronze badges 1- Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Bot Commented Dec 6, 2022 at 7:57
2 Answers
Reset to default 11If you are using yup, the formSchema must be a yup.object();
validationSchema: yup.object(formSchema)
The problem is your validationSchema: {formSchema}
is incorrect. You need to remove the bracket around formSchema
.
i.e.
const {values, handleChange, handleSubmit, errors} = useFormik({
initialValues: {
name: '',
address: '',
latitude: '',
longitude: '',
nit: '',
category: '',
email: '',
},
validationSchema: formSchema, // <--- use this instead of {formSchema}
validateOnChange: false,
onSubmit: () => console.log(values),
})