UNPKG

@modular-forms/react

Version:

The modular and type-safe form library for React

17 lines (16 loc) 436 B
import { safeParseAsync, } from 'valibot'; /** * Creates a validation functions that parses the Valibot schema of a field. * * @param schema A Valibot schema. * * @returns A validation function. */ export function valiField(schema) { return async (value) => { const result = await safeParseAsync(schema, value, { abortPipeEarly: true, }); return result.issues?.[0]?.message || ''; }; }