-
Notifications
You must be signed in to change notification settings - Fork 28
/
index.tsx
37 lines (33 loc) · 1.14 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import {
createElement,
useState,
useEffect,
forwardRef,
PropsWithChildren,
Dispatch as D,
SetStateAction as S,
ForwardedRef,
ReactElement
} from 'react';
import SchemaForm, { SchemaFormProps } from './SchemaForm';
import components from './customComponent';
import getKeysFromObject from './utils/getKeysFromObject';
import getObjectFromValue from './utils/getObjectFromValue';
import getValueFromObject from './utils/getValueFromObject';
import type { CustomComponentObject } from './types';
export default forwardRef(function(props: PropsWithChildren<SchemaFormProps>, ref: ForwardedRef<any>): ReactElement | null {
const { customComponent, ...otherProps }: SchemaFormProps = props;
const [custom, setCustom]: [
CustomComponentObject | undefined,
D<S<CustomComponentObject | undefined>>
] = useState(Object.assign(components, customComponent ?? {}));
useEffect(function(): void {
setCustom(Object.assign(components, customComponent ?? {}));
}, [customComponent]);
return <SchemaForm ref={ ref } customComponent={ custom } { ...otherProps } />;
});
export {
getKeysFromObject,
getObjectFromValue,
getValueFromObject
};