Hello i am new to react and i have a problem.. I want to set a Error Message and check if its empty.
This is my code:
const [errormsg, setErrorMsg] = useState("");
const register = (e) =>{
if(firstname === "" || lastname === ""){
setErrorMsg("Please fill out all Gaps!");
e.preventDefault();
}
if(errormsg === ""){
//DO SOMETHING
}
}
But everytime it skips the part where it should stop. Because even if lastname is empty it continues but i dont know why because it should stop there.
I also added the line e.preventDefault(); because i want to show the error message to the user and if it reloads after every submit this does not work