How to add examples to @tanstack/zod-form-adapter? #978
-
Currently there is a basic example on how to use Here is a real export const FormSchema = z.object({
email: z.string(),
companies: z.array(CompanySchema).optional().default([]),
});
export type UserForm = z.infer<typeof FormSchema>; If I specify the generics of the type import {formSchema, type UserForm} from './schemas/form.ts'
const form = useForm<UserForm, ZodValidator>({
defaultValues: {
email: "",
companies: [],
},
validatorAdapter: zodValidator(),
validators: {
onChange: FormSchema,
}
}); If I don't specify the types on the generic of the hook, then the types are not inferred. When you specify the Thanks you guys, this library is amazing by the way. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Do you think we need one more example for each adapter or would be enough to update the existing ones with form-level validation? That's probably the most common case anyway. If you want to give it a try on the zod example I'm happy to have a look at your PR, the project source is on Speaking of the type, you can define the default values like that and you won't need to explicitly type the form defaultValues: {
email: "",
companies: [],
} as UserForm |
Beta Was this translation helpful? Give feedback.
Do you think we need one more example for each adapter or would be enough to update the existing ones with form-level validation? That's probably the most common case anyway.
If you want to give it a try on the zod example I'm happy to have a look at your PR, the project source is on
examples/react/zod
Speaking of the type, you can define the default values like that and you won't need to explicitly type the form