react hook form - after first error cannot validate again

Viewed 39

Good Day!

Today i am faced with a problem regarding react hook form. I am setting a custom error using setError in case there is an error when loggin in.

The problem: After the first error, I cannot validate the form again. ex)

  • login fail with either wrong id or password => received error message from the backened.
  • error is set using setError
  • re-write the form and trying to submit again => cannot send login api to the backened.

Anyone had similar issues like myself?

const onValid = async (data) => {
    const res = await SignIn(data);
    if (res.data.result) {
        const result = setSessionKey(res.data.loginInfo.sessionKey);
        console.log(result);
        clearErrors();
    } else {
        return setError('loginFail', { message: 'login failed' });
    }
};
0 Answers
Related