How to properly use Formik's setError method? (React library)

后端 未结 4 1089
难免孤独
难免孤独 2021-02-04 00:26

I am using React communicating with a backend. Now trying to properly implement Formik (Form library).

Main question: How do I properly use Formik\'s setError me

4条回答
  •  旧时难觅i
    2021-02-04 00:34

     {
        // initialise error status <---- 1
        actions.setStatus(undefined); 
    
        setTimeout(() => {
    
          // setting error status <---- 2
          actions.setStatus({
            email: 'This is email already exists.',
            pswrd: 'This is password is incorrect',
          });
    
        }, 500);
      }}
      // destructuring status <---- 3
      render={({ handleSubmit, handleChange, handleBlur, values, errors, status }) => (
        
    // using error status <---- 4 {status && status.email ? (
    API Error: {status.email}
    ) : ( errors.email &&
    Validation Error: {errors.email}
    )} {status && status.pswrd ? (
    API Error: {status.pswrd}
    ) : ( errors.pswrd &&
    Validation Error: {errors.pswrd}
    )}
    )} />

提交回复
热议问题