Pablo
Pablo3w ago

Hello! It's me again, with the weird

Hello! It's me again, with the weird validation problems. So I dropped Zod and wrote the validations by hand and I created what I think is the smallest, most type correct example of what happens when you have optional numbers and you are using React Hook Form (I think this also happens with TanStack Form), React, NextJS and Convex. It's here: https://github.com/pupeno/convex-nextjs-playground The problem boils down to the form using "" to represent blanks, the API using null to represent blanks, and the database using undefined to represent blanks, which ends up creating a lot of types and a lot of conversion issues. My question for any kind soul here is, am I missing something? Can I simplify this somehow?
4 Replies
Pablo
PabloOP3w ago
In the readme of the repo I wrote down how the project works and also all the issues.
erquhart
erquhart3w ago
Personal opinion: the most basic qol improvement is to just not use unset values in your Convex db - use null instead. The advantage of null, even though I am no fan of null in js, is that it's serializable. That said, I do use unset/undefined in my dbs. I've found that data conversions at the db layer (the part of your Convex code that ends up forming semi-organically to centralize data integrity logic) are normal. Converting nulls to undefined for specific fields at the insert/patch point is just a part of normalization.
Pablo
PabloOP2w ago
What is qol? What are "unset values" in this context?
erquhart
erquhart2w ago
sorry, qol = "quality of life", unset values are what "undefined" represents inside of a convex database (as opposed to null, which is also supported in Convex db)

Did you find this page helpful?