Formik onSubmit never runs when the form is submitted
Clicking Submit does nothing and onSubmit is never calledShort answer
Formik runs onSubmit only after validation finds no errors. When the submit does nothing, log formik.errors first: a hidden validation error aborts the submit silently. Then check that handleSubmit is on the form element and that every field has an initial value. Reset isSubmitting if onSubmit is not async.
Fix it fast
1Find out which cause you have
Print Formik's errors next to the form. If the object is not empty, submission is being aborted.
<pre>{JSON.stringify({ errors: formik.errors, isSubmitting: formik.isSubmitting, submitCount: formik.submitCount }, null, 2)}</pre>2Match what you see, then jump to its fix
- 1
errors is not emptyValidation errors abort the submissionFix - 2
Nothing happens on click and submitCount stays 0handleSubmit is not attached to a formFix - 3
Console warns about an input changing from uncontrolled to controlledA field is missing from initialValuesFix - 4
isSubmitting stays true and the submit button is disabled afterwardsonSubmit never signals completionFix
- 1
What does the error look like?
Clicking Submit does nothing and onSubmit is never calledThe submit button stays disabled after the first click
Cause 1 of 4
Validation errors abort the submission
1Check
According to the Formik submission guide, when validation reports errors, submission is aborted, errors are stored and isSubmitting returns to false.
console.log(formik.errors)2Fix
Make initialValues, the validation schema and the field names the same set, and show each error so none is hidden.
<Formik
initialValues={{ email: '', password: '' }}
validationSchema={schema}
onSubmit={handleSave}
>3Verify
Submit with valid data. onSubmit runs and errors stays empty.
console.log(formik.errors)Confirmed by formik.org
Cause 2 of 4
handleSubmit is not attached to a form
1Check
Formik's API reference says handleSubmit should be passed to the form's onSubmit.
grep -rn "handleSubmit\|type=\"submit\"" src/2Fix
Wrap the fields in a form element with onSubmit={formik.handleSubmit} and give the button type="submit".
<form onSubmit={formik.handleSubmit}>
{/* fields */}
<button type="submit">Save</button>
</form>3Verify
Click the button; submitCount goes to 1.
console.log(formik.submitCount)Confirmed by formik.org
Cause 3 of 4
A field is missing from initialValues
1Check
The Formik reference says every field must be initialised in initialValues, otherwise React raises the uncontrolled-to-controlled error.
console.log(formik.values)2Fix
Add an initial value for every field name used by an input.
initialValues={{ name: '', age: 0, agree: false }}3Verify
formik.values lists every field before the user types.
console.log(formik.values)Confirmed by formik.org
Cause 4 of 4
onSubmit never signals completion
1Check
Formik resets isSubmitting by itself only if onSubmit returns a promise. A synchronous onSubmit has to call setSubmitting(false).
grep -rn "onSubmit" src/2Fix
Return a promise from onSubmit (make it async), or call setSubmitting(false) when done.
onSubmit={(values, { setSubmitting }) => {
save(values);
setSubmitting(false);
}}3Verify
Submit twice in a row; the second click is accepted.
console.log(formik.isSubmitting)Confirmed by formik.org
How do I stop it coming back?
- Render errors for every field while building the form.
- Keep field names, initialValues and schema keys identical.
- Make onSubmit async when it saves data.
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
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 fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
How to catch and handle a 422 from Axios in a Redux thunk
action.error.message is 'Rejected' and action.payload is undefined
A 422 means the server read the request but cannot process its content, so repeating it unchanged fails again.
4 causes, each with a fixWeb apps
axios gets 429 Too Many Requests from a React app
429 (Too Many Requests)
A 429 comes from the server or an API gateway, not from axios: your client sent too many requests in a window.
4 causes, each with a fixWeb apps
Axios request is not cancelled when a React component unmounts
A cancelled request is logged as an error in the catch block
Axios cancels a request when you pass it an AbortSignal and later call abort() on its controller.
4 causes, each with a fix