so I'm trying to post data to the server and get a response in return. somehow the API response change randomly Idk why, maybe you guys have any clue...
this is my code -
const [message, setMessage] = useState(false);
const [data, setData] = useState({
firstName: "",
lastName: "",
userName: "",
email: "",
password: "",
});
const [errorMessage, setErrorMessage] = useState(false);
const handleSubmit = (event) => {
event.preventDefault();
axios
.post("/register", {
fullname: data.firstName + " " + data.lastName,
username: data.userName,
email: data.email,
password: data.password,
})
.then((res) => {
console.log(res);
setMessage(res.data.success);
console.log(message);
if (message) {
console.log("success");
} else {
console.log("error");
}
});
};
const handleChange = (event) => {
setMessage(false);
setErrorMessage(false);
const newData = { ...data };
newData[event.target.id] = event.target.value;
setData(newData);
};
I have no clue what is causing this issue...
so the first time I get false, and then all the other calls are true, although I have a unique property for this property in my schema. sometimes it starts with false and then true and then all false.
second scenario
any idea guys? thanks for your help.