Formik: `isSubmitting` always true

Created on 5 Jul 2018  路  14Comments  路  Source: formium/formik

Current Behavior

After form is submitted, isSubmitting is not set to false

Steps to Reproduce

Submit form

Expected behavior

isSubmitting should be set to false

CodeSandbox Link:
https://codesandbox.io/s/vqjmnkvjn7

Note

This should be already fixed in #736, this issue is a placeholder so that I don't forget about it


  • Formik Version: 1.0.0-beta.4

Most helpful comment

+1 still an issue. Had to add a prop to check if errors were returned

All 14 comments

Will cut a release

Fixed in beta.5

Awesome!

Still an issue
Formik Version: 1.4.2

+1 here, seeing the same issue

Formik version: 1.4.0

+1 here, seeing the same issue

Formik version: 1.5.0

Same on last version

+1 still an issue. Had to add a prop to check if errors were returned

+1 still an issue Hotfix

onSubmit={(values, actions) => {
        setTimeout(() => {
          alert(JSON.stringify(values));
          // you have to clean up 
          actions.setSubmitting(false);
        }, 500);
      }}

@ahtashamabbasse setSubmitting(false) is required when not using async/promises. If you don't want to use setSubmitting, you can return a promise or use an async function. Without this requirement, Formik would never know when your timeout was complete, and would setSubmitting(false) immediately.

<Formik onSubmit={values => 
    new Promise(resolve => 
        setTimeout(() => {
            alert(JSON.stringify(values));
            resolve();
        }, 500);
} />

This seems like a surprising default- I would've expected it to set isSubmitting to false immediately if supplying a synchronous function.

@dpikt agreed, should probably change it in a future major version. It seems like a backwards compatibility thing.

Still problem in version 2.1.4.

It works when I use async await.

  onSubmit={async values => {
        await new Promise(resolve => setTimeout(resolve, 500));
        console.log(values)
      }}

but doesn't work on callback.

      onSubmit={values => {
        setTimeout(() => {
          console.log(values)
        }, 500);
      }}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

sibelius picture sibelius  路  3Comments

jaredpalmer picture jaredpalmer  路  3Comments

emartini picture emartini  路  3Comments

jaredpalmer picture jaredpalmer  路  3Comments

outaTiME picture outaTiME  路  3Comments