switzS
tRPC7mo ago
2 replies
switz

Preventing action from throwing error due to zod schema?

I have trpc creating server actions, fronted by a zod form data schema.

const createDatasetSchema = zfd.formData({
  name: zfd.text(
    z
      .string()
      .min(1, 'Name is required')
      .max(100, 'Name must be less than 100 characters')
      .lowercase()
      .regex(/[a-z0-9-_]/)
  ),
});


I don't want this to throw an error, I want to return errors to the frontend form (useActionState) so it can render what the errors are. Is there a good way to do this?
Was this page helpful?