Skip to content

Instantly share code, notes, and snippets.

View mrasadatik's full-sized avatar
🇧🇩
Focusing

Asaduzzaman Atik mrasadatik

🇧🇩
Focusing
View GitHub Profile
@mrasadatik
mrasadatik / use-validation-schema.ts
Last active March 10, 2024 05:35 — forked from nfantone/use-validation-schema.js
Use `yup` with `react-final-form` (TypeScript)
import { setIn } from "final-form";
import { useMemo } from "react";
import { ObjectSchema, ValidationError, InferType } from "yup";
/**
* Sets the `innerError.message` in an `errors` object at the key
* defined by `innerError.path`.
* @param {Record<string, string>} errors The object to set the error in.
* @param {ValidationError} innerError A `yup` field error.
* @returns {Record<string, string>} The result of setting the new error message onto `errors`.