I have a React JS form using useForm
library.
This is a popular library so I'm not sure this can be a bug but I'm getting into a state which seems incorrect. See the screenshot of the console in chrome below:
How can I have formState.isDirty
, but no formState.dirtyFields
?
It's a large, complex form but the isDirty state is achieved by human interaction with the form, with registration looking like this:
<input id="value" {...register("value")} defaultValue={variable.value} />
One other observation - the behavior seems to change when observed. For example, when adding this code to the form - it seems to work more as expected:
<div>
{formState.isDirty ? "DIRTY" : "CLEAN"}
<pre>dirty {JSON.stringify(formState.dirtyFields, null, 2)}</pre>
<pre>touched {JSON.stringify(formState.touchedFields, null, 2)}</pre>
</div>