Fairly new to programming period.
Basically I have form where upon clicking submit, this async function is triggered (returns a number based on the response from an axios post request).
Issue: I can't seem to get the right way to invoke this function(I never hit my console.log).
const handleSubmit = async (e : React.FormEvent<HTMLFormElement>) : Promise<number>=> {
e.preventDefault()
console.log("Submit Button Clicked")
const v1 = USER_REGEX.test(user);
const v2 = PWD_REGEX.test(pwd);
const v3 = EMAIL_REGEX.test(email)
if (!v1 || !v2 || !v3) {
setErrMsg("Invalid Entry");
return 0;
}
else {
console.log("Reached Else")
const config = {
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
}
return axios.post<UserResponse>('http:://localhost:5173/Register',
JSON.stringify({username : user, emailAddress: email, password: pwd}), config)
.then(res => {
console.log("Post Request Sent....got back response");
console.log(JSON.stringify(res.data));
//clear state and controlled inputs
setSuccess(true);
setUser('');
setPwd('');
setMatchPwd('');
return 1;
})
.catch(error => {
console.log("ERROR",error)
return 0;
});
}
}
<form onSubmit={void handleSubmit}>