React error
Hi everyone!
I’m facing the following error when I click a custom “Save Changes” button in my React app: “Uncaught Error: A React form was unexpectedly submitted.”
The button programmatically submits a form using form.submit() in the onClick handler. The form is a React component with an action tied to a server function.
From my understanding, React doesn’t recommend using form.submit() because it bypasses React’s form event system, and I should use requestSubmit() instead. However, I’m not entirely sure about the best way to implement this fix or if there are other potential pitfalls with programmatically submitting forms in React.
Can anyone shed some light or examples on how to properly programmatically submit forms in React without causing this error?
Thanks in advance!
1 Reply
What’s the reason you‘re execute the submit programmatically via onClick? Can’t you move everything you probably do into the submitHandler function?