React Hook Form: the submit button does nothing and onSubmit never runs
Clicking submit does nothing and onSubmit is never loggedShort answer
handleSubmit runs your onSubmit only when validation passes. When nothing happens, validation usually failed silently: pass a second callback or print formState.errors to see which field. Other causes are wrapping handleSubmit in an arrow function, which reloads the page, and a submit button that sits outside the form element.
Fix it fast
1Find out which cause you have
Give handleSubmit a second argument that logs the validation errors. If it prints, validation is the reason onSubmit stays silent.
<form onSubmit={handleSubmit(onSubmit, (errors) => console.log('invalid', errors))}>2Match what you see, then jump to its fix
- 1
The second (error) callback runs, or formState.errors is not emptyValidation failed, so the valid callback is skippedFix - 2
The page reloads on submit and onSubmit is not calledhandleSubmit is wrapped in an arrow functionFix - 3
Clicking the button does nothing, and the button is placed outside the form tag in the JSXThe submit button is outside the form elementFix - 4
Submitting an inner form in a modal also fires the outer form's handlerA nested form submits the outer form as wellFix
- 1
What does the error look like?
Clicking submit does nothing and onSubmit is never loggedThe page reloads when the form is submitted
Cause 1 of 4
Validation failed, so the valid callback is skipped
1Check
handleSubmit validates the inputs first. Only if they pass does it call onSubmit; if they fail it calls the optional second callback with the errors. A required field the user left empty is enough.
const { register, handleSubmit, formState: { errors } } = useForm();
console.log(errors);2Fix
Fix the field the errors name, or show errors next to the inputs so users see them too.
<input {...register('email', { required: 'Email is required' })} />
{errors.email && <p role="alert">{errors.email.message}</p>}3Verify
Fill the field and submit. onSubmit now logs the form data.
# click submit with the browser console openConfirmed by react-hook-form.com
Cause 2 of 4
handleSubmit is wrapped in an arrow function
1Check
handleSubmit(onSubmit) returns a function that takes the event. Wrapping the call in an arrow function runs it without the event, so the browser performs its default submit.
grep -rn "onSubmit={" src/2Fix
Pass the result of handleSubmit directly.
// wrong
<form onSubmit={() => handleSubmit(onSubmit)}>
// right
<form onSubmit={handleSubmit(onSubmit)}>3Verify
Submit the form. The page does not reload and onSubmit runs once validation passes.
# click submit and watch the network tab for a full page loadConfirmed by react-hook-form.com
Cause 3 of 4
The submit button is outside the form element
1Check
A button that is not inside the form does not submit it. Look at where the button sits in the JSX, for example in a modal footer.
grep -rn "type=\"submit\"" src/2Fix
Link the button to the form with the native form attribute, or call handleSubmit(onSubmit) in the button's onClick.
<form id="profile-form" onSubmit={handleSubmit(onSubmit)}>...</form>
<button type="submit" form="profile-form">Save</button>3Verify
Click the button. onSubmit runs, or the error callback prints the errors.
# click the button with the console openConfirmed by react-hook-form.com
Cause 4 of 4
A nested form submits the outer form as well
1Check
When one form sits inside another form's tree, as with a modal, the submit event bubbles up to the outer form.
grep -rn "<form" src/2Fix
Stop the event from bubbling in the inner form's submit handler.
<form onSubmit={(e) => { e.stopPropagation(); handleSubmit(onInnerSubmit)(e); }}>3Verify
Submit the inner form. Only its own handler runs.
# click the inner submit with the console openConfirmed by react-hook-form.com
How do I stop it coming back?
- Always pass the error callback or render formState.errors while building a form.
- Keep the submit button inside the form, or give it the form attribute.
- Await async work in onSubmit so formState.isSubmitting stays true until it finishes.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
The validation message never appears under an MUI X Date Picker
The field never turns red after a failed validation
A DatePicker does not take helperText or error as direct props.
3 causes, each with a fixWeb apps
React Hook Form isDirty does not go back to false
formState.isDirty is false after setValue
React Hook Form sets isDirty by comparing the current values with defaultValues.
4 causes, each with a fixWeb apps
react-hook-form: an optional number input gives NaN instead of a number or null
Validation fails on an optional numeric field
valueAsNumber returns NaN when a value cannot be converted, and setValueAs is ignored while valueAsNumber is on.
3 causes, each with a fixWeb apps
A Zod refinement error does not appear or does not clear in React Hook Form
The refinement error never shows until every other field is valid
Three Zod and React Hook Form rules explain it.
4 causes, each with a fixWeb apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Astro Code component fails inside a React component
Astro components cannot be rendered directly via function call
Astro components such as Code only exist on the server and render static HTML.
2 causes, each with a fix