Form level isDefaultValue always false.
I have code like this in my form:
The
isDefaultValue
there is always false. I tried also doing reset inside useEffect, also with delay (setTimeout), with both keepDefaultValues true and false. Nothing changes.
I tried to investigate which of the fields is not default:
And according to this, all fields are at their default value.
Any idea what might be happening?
My version of @tanstack/react-form is 1.14.1
10 Replies
quickest-silver•2mo ago
could you share your form hook? The snippet that creates
useAppForm
like-goldOP•2mo ago
Sure!
quickest-silver•2mo ago
I see that I worded the previous message poorly. I don't see anything noteworthy here, but I was looking for the following:
because in the code,
isDefaultValue
is as you expect. A check for every field and seeing if isDefaultValue
is truelike-goldOP•2mo ago
I see. It has structure like this:
Then in another component I do:
Right, but if any of the fields changed, they would have isDefaultValue false, right? What I find strange is the inconsistency between the field-level isDefaultValue and form level isDefaultValue.
Is there some other state than the state covered by this?
quickest-silver•2mo ago
The internal state is
the hook creation also looks normal ... strange.
try checking
form.fieldMetaDerived.state
instead of fieldInfo
like-goldOP•2mo ago
Ok, plot thickens! 😄
I added this:
The output is:
So in the useEffect hook, all is good. It's just the subscribe where it isDefaultValue is false and isDirty is true.
quickest-silver•2mo ago
hold up ...
your selector and destructuring ...
you named
isSubmitting
a variable called isDefaultValue
like-goldOP•2mo ago
omg
I am so sorry to have wasted your time 😐
quickest-silver•2mo ago
no worries, I missed it too :KEKW:
classic JavaScript moment though. If you ask me, if your destructuring array is not the same size as the input it ought to throw an error
like-goldOP•2mo ago
Changed it to object right away to avoid future mistake like this 😄