Error Handling for Null Values in Drizzle-Zod + Shadcn Form (React-Hook-Form)
The error message indicates that the value property of the field object can be null, but the Input, Checkbox components value prop do not accept null as a valid type. It only accepts string, number, readonly string[], or undefined.
17 Replies
👋 Yes, without
.notNull
the default for the DB is null
.
Maybe you can try to override your zod schema?:
I did this but it's not changing the error:
Do you have some default/initial values somewhere that come from a query? (that you set in react hook form)
Here is my react hook form
So the error is for
verified
or isBuyer
?All fields that don't have notNull() in my db schema
foundingYear: null,
is expected?and the Phone component surprisingly isn't having an issue despite phone not having notNull() in my db
Yeah if the user doesn't mention the founding year in the form we store it as null
because
value={field.value ?? undefined}
This is what I do too, ?? undefined
😬Ah yeah that was my temporary fix haha.
I don't know if there is a better solution. We are mixing 2 worlds: front-end that wants
undefined
as nullable value and db that only knows null
The beauty of "full-stack", I suppose haha.
yeah .. I am a Remix Run user, so close to what html expect and I always have to remap my 'models' or deal with
?? undefined
could be cool to have an option somewhere to transform null to undefined
is it Tan query behind the scene?Yeah!
I wonder if there is something that could transform that
Just an idea. in your schema override, can you try to add a
.default(undefined)
in one of the fields?