I want to store the state of my React Final Form somewhere. Right now that is in a React Hook. I'm currently using useMethods
, similar to useState
.
The form I currently have is part of a multi-step process, and when I navigate to another page which the form is not on, it is unmounted (of course). When re-mounted, I want to provide the form with initial values (available here).
The problem is that when my state changes the form re-renders and I always end up in an endless loop, because:
- The
FormSpy
stores changes in the form - The state is changed
- Form is re-rendered
- The
FormSpy
stores changes in the form - And so on...
I also have a problem that when initial values are provided, the field state is not populated (dirty, touched, etc.), so the form looks strange when re-mounted because some of the labels are tied to the meta fields. It seems like we need some kind of way to store all of the form state, not only the values as the component which contains the Form
can unmount and re-mount n number of times.
What I want:
- Changes to immediately to be stored in my state
- Re-renders somehow remember (I can store this in my own state if needed) the touched, dirty, etc. state
My starting point was to look at Auto-save with Debounce (although I don't need to debounce, since I'm storing it locally).
What is the best way to handle this?