Created
June 12, 2019 18:37
-
-
Save devakone/40025da341e410bdeed4e10a4e7398bf to your computer and use it in GitHub Desktop.
How to use the useTranslateFormErrors hook with Formik's component render method.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
<Formik component={ContactForm} />; | |
... | |
import useTranslateFormErrors from '../../hooks/use-translate-form-errors'; | |
const ContactForm = ({ | |
handleSubmit, | |
handleChange, | |
handleBlur, | |
values, | |
errors, | |
touched, | |
setFieldTouched | |
}) => { | |
useTranslateFormErrors(errors, touched, setFieldTouched); | |
return ( | |
<form onSubmit={handleSubmit}> | |
<input | |
type="text" | |
onChange={handleChange} | |
onBlur={handleBlur} | |
value={values.name} | |
name="name" | |
/> | |
{errors.name && <div>{errors.name}</div>} | |
<button type="submit">Submit</button> | |
</form> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment