I would guess some combination of the above might solve your usecase, depending on the exact UX you need. You can also use the keepDirtyOnReinitialize prop to only reset the parts of your form that haven't been touched. Stack Overflow How to create an upload file field using react-final-form Ask Question Asked 1 year, 9 months ago Modified 1 year, 9 months ago Viewed 2k times 0 I am trying to create an upload field ( class based ) using react-final-form Strangely documentation does not contain any info regarding this. However if you actually want this, but need to modify it, the comparison behaviour can be configured using the initialValuesEqual prop ( docs here), to do a deep comparison on the initialValues object for example. I would prefer a configuration to actually completely turn off this reinitialisation behaviour, but I can't find one in the docs. To solve the general problem, if you just want to turn off the form resetting, what I've done is just move my initialState, which never changes, out to a variable so that it's the same reference on every render and therefore always appears to be the same to final-form with the default behaviour. This means that if you create a new object in the render, even if it's the same, the entire form resets when some state changes, the render function re-runs, and a new object with a new reference is created for initialValues. By default, whatever you pass to initialValues is compared against the previous one using shallow equals, i.e. The problem is that when initialValues changes the entire form reinitialises. The worlds leading companies use Formik to build forms and surveys in React and React Native. InitialValues= <- creates a new object on every render React hooks and components for hassle-free form validation. React Final Form is a thin React wrapper for Final Form, which is a subscriptions-based form state management library that uses the Observer pattern, so only the components that need updating are re-rendered as the form’s state changes. The problem is here (from your codesandbox)
0 Comments
Leave a Reply. |