Unable to Type in Field

后端 未结 3 1067
执念已碎
执念已碎 2020-12-07 04:43
interface FormValues {
  friendEmail: string;
}

  const initialValues: FormValues = {
    friendEmail: \'\',
  };

export const Page: React.FunctionComponent

        
3条回答
  •  星月不相逢
    2020-12-07 04:56

    I think there are a couple of issues in your codebase.

    1. onChangeText={handleChange('friendEmail')}. It will trigger the handleChange while rendering the component not when you are actualy typing in the input box.
    2. handleChange function of Formik takes React.ChangeEvent instead of value. Check here . While onChangeText of react-native provides changed text of the input not event. Check here

    You can use setFieldValue function for this case:

    
        {({
          handleChange,
          handleBlur,
          handleSubmit,
          isSubmitting,
          values,
          setFieldValue
        }) => {
        const setEmail = (email) => {
          setFieldValue('friendEmail', email)
        }
        return (
          
            
              
                
              
            
          
        )
        }}
      
    

    Please Note: I've never used formik with react-native. Just trying to connect the dots.

提交回复
热议问题