Open jitenderchand1 opened 4 years ago
Formik should not lose its state if the page isn't physically reloaded and if it and every one of its ancestors retains the same identity in the hierarchy between renders, independent of what happens in React Router. That said, React Router might be switching a parent in the hierarchy, like the page template. If the only components that change are the Siblings of Formik, this can be solved by adding a key={} to Formik that doesn't change. If any of Formik's ancestors changes component types or ends up with a different key={}
, there is no way to retain Formik's state, and it would have to be managed outside of React State (redux, etc), or the Formik component moved outside of the changing hierarchy.
I can't really give any more insight without a minimal CodeSandbox reproduction of your issue.
🐛 Bug report
Current Behavior
When I do component shows up for a second then hide itself.
I used
history.goBack()
theformikProps.dirty
to determine whether to show prompt but the Formik rerender itself again and setformikProps.dirty
to false when I dohistory.goBack()
Expected behavior
While rerendering Formik should not retain state
Reproducible example
I am using react-router-navigation-prompt to warn the user to save unsaved changes.
Your environment