Реагирует на жизненный цикл JS Field Formik, у Field child не те же реквизиты Parent Formik - PullRequest
0 голосов
/ 14 марта 2019

У меня есть родительский компонент с Formik

Компонент Родитель

<Formik
      validationSchema={validationSchema}
      render={({ props }) => (
       //… more code 
       <ChildrenComponent props={props} />
      )}
   />

Детский компонент

import ExternalLib from "external_lib";
function ChildrenComponent ({classes, ...props}) {
    <ExternalLib
          catalogos={state.nacionalidades}
          classes={classes}
          name={"Applicant.TypeOfPerson.Nationality"}
          label={"Nacionalidades"}
          setFieldValue={props.setFieldValue}
      />
}

Внешняя библиотека

Эта внешняя библиотека будет иметь функцию автозаполнения текста для поиска национальностей, стран и т. Д.

export default class ExternalLib extends Component {
//…more code
return (
       <div ref={this.divWidth}>
                <Formik> // The lifecycle of this Formik is different than TransactForm for that reason 
                         //my  Field  called "Applicant.TypeOfPerson.Nationality" doesn’t save the 
                         //value unless if I use the registerField of this Formik and do the same with 
                         //the props.registerField from parent Formik. And the 
                         //validationSchema from Formik parent doesn’t work with this field for the 
                         //same reason (the lifecycle of this Formik is different than Formik parent).
                         //Is there a way to pass the Formik props Parent in the Formik of this 
                         //library?
            <Field
name={this.props.name} // the props.name is  //__"Applicant.TypeOfPerson.Nationality” sent by the children component
            type="text"
            label={this.props.label}
            fullWidth
            component={TextField}
            autoComplete="off"
            required
            onKeyUp={this.onKeyUp}
            InputProps={{
              onBlur:this.onBlur,
              classes: {
                  input: "Field-fontFamily",
                }
            }}
          />
        </Formik>
        {suggestionsListComponent}
      </div>
    );
}

Жизненный цикл этого Formik отличается от TransactForm, поэтому мое поле под названием "Applicant.TypeOfPerson.Nationality" не сохраняет значение, если только я не использую registerField этого Formik и не делаю то же самое с props.registerField из родитель Формик. И validationSchema от родительского Formik не работает с этим полем по той же причине (жизненный цикл этого Formik отличается от родительского Formik). Есть ли способ передать родительский объект Formik в Formik этой библиотеки?

Formik версия 1.4.2

...