formik-validation-adaptors
Version:
A lightweight utility to integrate Zod and Joi validation with Formik.
14 lines (13 loc) • 389 B
JavaScript
/**
* Converts Joi or Zod errors into a Formik-compatible error object.
*
* @param errors - Array of error details from Joi or Zod
* @returns A structured error object.
*/
export const formatValidationErrors = (errors) => {
return errors.reduce((acc, err) => {
if (err.path.length > 0)
acc[err.path.join(".")] = err.message;
return acc;
}, {});
};