Next.js Discord

Discord Forum

React Error: Uncaught Error: A React form was unexpectedly submitted

Unanswered
Kurilian Bobtail posted this in #help-forum
Open in Discord
Kurilian BobtailOP
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 provide guidance or examples on how to properly programmatically submit forms in React without causing this error? Thanks in advance!

0 Replies