formik validate code example
Example 1: formik and yup
import React from 'react';
import { Formik, Field, Form, ErrorMessage } from 'formik';
import * as Yup from 'yup';
const SignupForm = () => {
return (
{
setTimeout(() => {
alert(JSON.stringify(values, null, 2));
setSubmitting(false);
}, 400);
}}
>
);
};
export default SignupForm;
Example 2: what triggers formik validate
const Input = ({ field, form }) => {
useEffect(() => {
form.validateForm();
}, []);
return (
{form.errors[field.name] && (
{form.errors[field.name]}
)}
);
};