onChange on TextInput Not Working Inside Formik

前端 未结 1 1874
无人及你
无人及你 2020-12-12 06:23

Generally allows you to type even when you\'re just specifying a placeholder. However, when using within the Formik form, I am unable to type

相关标签:
1条回答
  • 2020-12-12 06:30

    In your case if your TextInput returns value at first parameter like you use all right. But you mistake give name to field:

    <TextInput
      name="friendEmail"
      placeholder="Email"
      onChangeText={setEmail}
      autoCapitalize="none"
    /> 
    

    Formik doesn't know where to set your value if you don't give name to field. And also you can do like:

    <TextInput
      name="friendEmail"
      placeholder="Email"
      onChangeText={(val) => {
        setFieldValue('friendEmail', val)
        setFieldTouched('friendEmail', true, false);
      }
      autoCapitalize="none"
    /> 
    

    My advice is to modify or write wrapper for TextInput. And field should return onChange first parameter name, and second value. It will be more useful. And you can read more about your problem on official docs.

    0 讨论(0)
提交回复
热议问题