@explita/daily-toolset-form
Version:
A lightweight form toolkit for React built with developer ergonomics in mind. Includes a flexible Form component, useForm, useField, and useFormContext hooks for managing form state and validation with ease. Designed to simplify complex forms while remain
20 lines (19 loc) • 906 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ErrorMessage = ErrorMessage;
const react_1 = __importDefault(require("react"));
const __1 = require("../");
function ErrorMessage() {
var _a;
const { name } = (0, __1.useFieldName)();
//@ts-ignore
const { errors, errorParser } = (0, __1.useFormContext)();
// @ts-ignore
const error = name ? errors === null || errors === void 0 ? void 0 : errors[name] : undefined;
if (!error || !name)
return null;
return (react_1.default.createElement("p", { "data-error": "true", style: { color: "red", fontSize: "0.75rem" } }, (_a = errorParser === null || errorParser === void 0 ? void 0 : errorParser(error)) !== null && _a !== void 0 ? _a : error));
}