@undermuz/react-json-form
Version:
Generate JSON-based forms with react
62 lines (61 loc) • 1.15 kB
JavaScript
// src/array-form/ArrayFormItem.tsx
import { useCallback, useEffect } from "react";
import FlatForm from "../flat-form/FlatForm.mjs";
import { jsx } from "react/jsx-runtime";
var ArrayFormItem = (props) => {
const {
id,
parentId,
value,
scheme,
level,
isShow = true,
primary = false,
onRef,
children,
onChange,
onError
} = props;
const change = useCallback(
(newValue) => {
onChange(newValue, id);
},
[id, onChange]
);
const setErrors = useCallback(
(newErrors) => {
onError(newErrors, id);
},
[id, onError]
);
const ref = useCallback(
(ref2) => {
onRef?.({ id, ref: ref2 });
},
[onRef]
);
useEffect(() => {
if (!id) {
console.error("ArrayFormItem: props id is required");
}
}, []);
return /* @__PURE__ */ jsx(
FlatForm,
{
id: `${parentId}-${id}`,
ref,
level,
isShow,
primary,
scheme,
value,
onChange: change,
onError: setErrors,
children
}
);
};
var ArrayFormItem_default = ArrayFormItem;
export {
ArrayFormItem_default as default
};