Closed
Description
Description
I have a function called handleSubmitForm
tied to my form onSubmit
. The function does some checks before calling the handleSubmit
function of the useChat
.
const handleSubmitForm = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
// code
if (!condition) {
// more code
return;
}
handleSubmit(e);
};
The issue arises when the condition fails in handleSubmitForm
and it returns without triggering handleSubmit
. Now when the condition is met next time, handleSubmit
fails to execute. I commented return
in the conditional statement and it worked. I then wrapped handleSubmit
in an else block like below and then it stopped working again.
const handleSubmitForm = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
// code
if (!condition) {
// more code
return;
} else {
handleSubmit(e);
}
};
The same thing happens with append
as well. I am stuck because of it.