UNPKG

@modular-forms/react

Version:

The modular and type-safe form library for React

14 lines (13 loc) 355 B
/** * Creates a validation functions that parses the Zod schema of a field. * * @param schema A Zod schema. * * @returns A validation function. */ export function zodField(schema) { return async (value) => { const result = await schema.safeParseAsync(value); return result.success ? '' : result.error.issues[0].message; }; }