How do you handle zod with i18n and react-hook-form? (next-intl)
Unanswered
Sun bear posted this in #help-forum
Sun bearOP
const formSchema = (t: (arg: string) => string) => z.object({
username: z.string().min(3, {
message: t("username.errors.minlength")
}).max(20, { message: t("username.errors.maxlength") }),Do you have a better approach?
5 Replies
Japanese Bobtail
you should go through every chapter ideally, they talk you through most of the base cases
@Sun bear js
const formSchema = (t: (arg: string) => string) => z.object({
username: z.string().min(3, {
message: t("username.errors.minlength")
}).max(20, { message: t("username.errors.maxlength") }),
Do you have a better approach?
Blue orchard bee
This looks completely fine to me as long as you have a formSchema builder to quickly spread these through the application.
You can even use string interpolation with i18n to further expand the validation :D