David Huson
TTCTheo's Typesafe Cult
•Created by David Huson on 7/25/2024 in #questions
Weird field error with React Hook Form (using Shadcn Form)
I figured it out. If anyone else runs into a similar problem. The issue was with my schema shape. Since the form uses the useFieldArray hook, the dynamic fields are named using the following convention:
record.${index}.${name}
but the schema just had a single z.object with the names of the fields as the keys. The fix was to create an outer z.object named record
and inside it have an array of z.objects with the field schemas in it.2 replies