axrising
@axrising

Как вывести динамические поля Formik?

Есть объект contacts который приходит из сервера.
type ContactsType = {
  github: string
  vk: string
  facebook: string
  instagram: string
  twitter: string
  website: string
  youtube: string
  mainLink: string
}

Как добавить в Formik динамический key в значениях name и value?
Буду благодарен за ответ

Текущий код (не рабочий)
initialValues={{
          fullName: profile.fullName,
          lookingForAJob: profile.lookingForAJob,
          lookingForAJobDescription: profile.lookingForAJobDescription,
          aboutMe: profile.aboutMe,
          contacts: profile.contacts,
        }}

{Object.keys(profile.contacts).map((key) => {
                  return (
                    <React.Fragment>
                      <TextField
                        key={key}
                        className={classes.gutters}
                        margin='dense'
                        fullWidth
                        variant='outlined'
                        id='standard-basic'
                        name={`contacts.${key}`}
                        label={key}
                        value={values.contacts[key]}
                        onBlur={handleBlur}
                        onChange={handleChange}
                        error={touched.contacts?.github && Boolean(errors.contacts?.github)}
                        helperText={touched.contacts?.github && errors.contacts?.github}
                      />
                    </React.Fragment>
                  )
                })}
  • Вопрос задан
  • 190 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы