TypeError: Cannot convert undefined or null to object #986
Unanswered
jacekwilczynski
asked this question in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi! Let me first say a big thank you for this library - I'm migrating from RHF due to superior DX and typesafety and I'm pretty happy so far.
I'm on v0.34.0. There's one surprise I've encountered: when I did something like this:
After order item removal with
removeFieldValue
somewhere else, I get an error when my input component callsfield.handleChange
. The error is here, becausestate.meta
did not have anerrorMap
field.This seems to happen in two cases:
form.pushFieldValue
gets called before<form.Field name="orderItems" type="array">
was ever rendered. Thenform.state.fieldMeta.orderItems
is{isTouched: true, isBlurred: true, isDirty: true}
. This can be resolved by callingform.useField({ name: 'orderItems', mode: 'array" })
right afteruseForm
to make sure the field meta gets set up even if the field has not been rendered yet.pushFieldValue
call doesn't immediately error, but the automatically added order item object is missing some properties and the field meta for one of them is also a partial of proper field meta, like above.. This can be solved by wrapping the listener insetTimeout(..., 0)
.Are those bugs or am I doing something wrong? If needed, I can prepare a CodeSandbox and create an issue.
Beta Was this translation helpful? Give feedback.
All reactions