jaredpalmer / formik-persist

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

Formik-Persist doesn't persist my data on refresh #30

Closed SVRGIM closed 4 years ago

SVRGIM commented 4 years ago

0

Hi I am currently using Formik and Formik-Persist to make a form wizard with 10 questions. On refresh (sometimes on first refresh, sometimes on second refresh) it happens to reset the values. Why?

Below you have the code. I didn't put the array of routes, but that's all.


      initialValues={{
        idealWeight: "",
        age: 0,
        kg: 0,
        cm: 0,
        kgFromBMI: 0,
        RMB: 0,
        bodyRecomposition: 0,
        gender: "",
        currentLifestyleEvaluationIMet: "",
        mainReason: [],
        currentHealthRisk: [],
        diabetesHistory: "",
        environment: "",
        email: "",
        password: "",

        activityLevel: 1.2
      }}
      onSubmit={() => {
        console.log("something");
      }}
    >
          <div className={styles.slide}>
            <Form>
              <ProgressBar
                progress={((findIndexOfCurrentRoute + 1) / pages.length) * 100}
              />
              <Switch>
                <Redirect from="/signup" exact to="/signup/idealWeight" />
                <div
                  className={styles.slide__center}
                  style={{ paddingTop: "3em" }}
                >
                  {pages.map((page: any, index: number) => (
                    <div style={{ width: "100%" }}>
                      <Route key={index} path={`/signup/${page.forRoute}`}>
                        {page.page}
                      </Route>
                    </div>
                  ))}
                </div>
              </Switch>
              <Persist name="signup-form" debounce={1} />
            </Form>
          </div>
        );
      }}
    </Formik>```
abruzy commented 2 years ago

@SVRGIM did you find a solution to this? Currently facing this same issue.

munishchoudhary204 commented 1 year ago

I found a solution , Just pass enableReinitialize prop to Formik

munishchoudhary204 commented 1 year ago

@SVRGIM did you find a solution to this? Currently facing this same issue.

I found a solution , Just pass enableReinitialize prop to Formik