Fix form fields set to blank when changing watched values
Fix #392 (closed)
The number of line changes is absolutely not related to the brain power I put in this one.
My analysis goes like this:
- As some fields as watched in the form (ex:
noReturnAddress), changing these fields will change the form state (in the React sense of the term)>
- The nested component
TextFieldGroupsubscribes to form state changes as it uses the
FormContext(https://react-hook-form.com/advanced-usage#FormProviderPerformance). In short, changes in the form state will trigger re-renders of
- Somehow, the value of the
TextFieldGroupis kept in the form state but the re-render of the component sets it to a blank value.
My fix was then to retrieve the value of the
TextFieldGroup from the form state and set it as the
defaultValue of the
TextFieldGroup so that it is restored on re-rendering.