how can I make sure that handleOpen only executes after all the states (nameError, emailError, messageError) have been updated? My problem is that since state doesn't update immediately, sometimes handleOpen executes when it shouldn't.
const handleSend = (e) => {
e.preventDefault();
if (name === "") {
setNameError(true);
}
if (email === "") {
setEmailError(true);
setEmailErrorMessage("Please type your email!");
}
if (!email.includes("@")) {
setEmailError(true);
setEmailErrorMessage("Invalid email address");
}
if (message === "") {
setMessageError(true);
}
if (!nameError && !emailError && !messageError) {
handleOpen();
}
};
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW
Comments
Post a Comment