jaredpalmer / formik-persist

💾 Persist and rehydrate a Formik form to localStorage
MIT License
377 stars 56 forks source link

Do not persist isSubmitting #26

Open hendrul opened 5 years ago

hendrul commented 5 years ago

If I go back to a persisted form isSubmitting is true https://codesandbox.io/embed/recursing-hodgkin-bcyvp

leibowitz commented 4 years ago

I noticed when the isSubmitting is set back to false (after submit), the Persist component doesn't seem trigger a component update. I tried checking the comparison in componentDidUpdate to see if the isEqual check might be returning wrong result, but that doesn't seem to be the case.

While trying to fix this, I realised formik-persist is built with an old version of formik (1.x). I tried upgrading to formik 2.x but couldn't get it to work the same way.

Anyhow, in the meantime, I used this as a workaround

{!isSubmitting && <Persist name="form-id" />}

Does the job for me. It might do for you too, but I let you be the judge

tomcobley commented 2 years ago

The {!isSubmitting && <Persist name="form-id" />} workaround didn't work for me.

A better workaround for this (in my case at least) is to call setFieldValue() without parameters after calling setSubmitting(false) to force the new value of isSubmitting to be persisted.

fordooo commented 1 year ago

I was finally able to clear isSubmitting: true by calling window.localStorage.removeItem("form-id") in the onSubmit along with using {!isSubmitting && <Persist name="form-id" />}