Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handleSubmit not being called conditionally #1394

Open
msaaddev opened this issue Apr 19, 2024 · 0 comments
Open

handleSubmit not being called conditionally #1394

msaaddev opened this issue Apr 19, 2024 · 0 comments
Labels
ai/ui bug Something isn't working

Comments

@msaaddev
Copy link

msaaddev commented Apr 19, 2024

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.

@lgrammel lgrammel added bug Something isn't working ai/ui labels Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ai/ui bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants