Answer the question
In order to leave comments, you need to log in
How to map an array along with Formik's errors object?
How to map so that a class is added to className if there is an error in the erorrs object with a specific name that substitutes .map?
let fieldsContacts =[
{id: 1, name: 'fullName'},
{id: 2, name: 'aboutMe' },
]
<Formik>
{({errors, touched => (
<Form>
{fieldsContacts.map(field =>
<Field name={field.name} className={errors.field.name && touched.field.name && classes.errorField} id={field.name}/>
)}
</Form>
)}
</Formik>
<Field name="fullName" className={errors.fullName && touched.fullName && classes.errorField} id="fullName"/>
<Field name="aboutMe" className={errors.aboutMe && touched.aboutMe && classes.errorField} id="aboutMe"/>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question