react-hook-form-builder
Version:
light weight schema Form builder for react-hook-form
21 lines (20 loc) • 1.11 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { FormProvider } from "react-hook-form";
import { isFunction } from "../../utils/helpers";
import ElementParser from "../elementParser";
var FormBuilder = function (_a) {
var methods = _a.methods, schema = _a.schema, onSubmit = _a.onSubmit, children = _a.children;
return (_jsx(FormProvider, __assign({}, methods, { children: _jsxs("form", __assign({ onSubmit: onSubmit && isFunction(onSubmit) ? methods.handleSubmit(onSubmit) : undefined }, { children: [children, schema === null || schema === void 0 ? void 0 : schema.map(function (schema, index) { return (_jsx(ElementParser, { schema: schema }, index)); })] })) })));
};
export default FormBuilder;