Skip to content

Commit 4c604b5

Browse files
committed
fix: component type
1 parent 28721d2 commit 4c604b5

File tree

2 files changed

+43
-40
lines changed

2 files changed

+43
-40
lines changed

src/v2/components/FormGenerator.tsx

+17-13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
/* eslint-disable react/no-array-index-key */
12
/* eslint-disable react/jsx-no-useless-fragment */
23
/* eslint-disable no-use-before-define */
34
/* eslint-disable react/require-default-props */
45
/* eslint-disable consistent-return */
56
/* eslint-disable react/jsx-key */
6-
import { Suspense, useContext, useMemo } from "react";
7+
import { Fragment, Suspense, useContext, useMemo } from "react";
78
import { ISchema, ISchemaCore } from "../types";
89
import ComponentContext from "../contexts/ComponentContext";
910
import { getSchemaName } from "../logic/createForm";
@@ -115,18 +116,21 @@ export function SchemaComponent({
115116
wrapper={wrapper}
116117
schema={schema}
117118
>
118-
{({ value, container: Container }) => value?.map((data: any, index: number) => (
119-
// eslint-disable-next-line react/no-array-index-key
120-
<Container schema={schema} data={data} key={`${parent}-${identity}-${index}-${generatedKey}`}>
121-
<FormGenerator
122-
parent={`${identity}.${index}`}
123-
schemas={updateSchemasAttributTitle(schema.childs, index)}
124-
fallback={fallback}
125-
fallbackComponentNotRegisterd={fallbackComponentNotRegisterd}
126-
fallbackVariantNotRegistered={fallbackVariantNotRegistered}
127-
/>
128-
</Container>
129-
))}
119+
{({ value, container: Container }, indexContainer) => (
120+
<Fragment key={indexContainer}>
121+
{value?.map((data: any, indexValue: number) => (
122+
<Container schema={schema} data={data} key={`${parent}-${identity}-${indexContainer}-${indexValue}-${generatedKey}`}>
123+
<FormGenerator
124+
parent={`${identity}.${indexValue}`}
125+
schemas={updateSchemasAttributTitle(schema.childs, indexValue)}
126+
fallback={fallback}
127+
fallbackComponentNotRegisterd={fallbackComponentNotRegisterd}
128+
fallbackVariantNotRegistered={fallbackVariantNotRegistered}
129+
/>
130+
</Container>
131+
))}
132+
</Fragment>
133+
)}
130134
</Component>
131135
</Suspense>
132136
);

src/v2/contexts/ComponentContext.tsx

+26-27
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,50 @@
1-
import { createContext } from "react";
1+
import { createContext, FC } from "react";
22
import { ISchemaFieldCore } from "../types";
33

4-
export type IComponentContainer<T = any> = (
5-
_propsContainer: {
6-
data: T extends ISchemaFieldCore ?
7-
NonNullable<T["initialValue"]>[0] extends object ?
8-
NonNullable<T["initialValue"]>[0] : any
9-
: any; children: any; schema: T
10-
}) => any
4+
export type IComponentContainerProps<T = any> = {
5+
data: T extends ISchemaFieldCore ?
6+
NonNullable<T["initialValue"]>[0] extends object ?
7+
NonNullable<T["initialValue"]>[0] : any
8+
: any; children: any; schema: T
9+
}
1110

12-
export type IComponent<T> = (_props: {
11+
export type IComponentProps<T> = {
1312
schema: T;
1413
wrapper?: any;
1514
schemas?: any[];
16-
}) => any
17-
export type IComponentGroup<T> = (_props: {
15+
};
16+
export type IComponentGroupProps<T> = {
1817
schema: T;
1918
wrapper?: any;
2019
children: any;
2120
schemas?: any[];
22-
}) => any
23-
export type IComponentArray<T> = (_props: {
21+
};
22+
export type IComponentArrayProps<T> = {
2423
schema: T;
2524
wrapper?: any;
2625
schemas?: any[];
27-
children: (_propsChildren: {
26+
children: FC<{
2827
value: any[],
29-
container: IComponentContainer<T>
30-
}) => any;
31-
}) => any
32-
export type IComponentObject<T> = (_props: {
28+
container: FC<IComponentContainerProps<T>>
29+
}>
30+
};
31+
export type IComponentObjectProps<T> = {
3332
schema: T;
3433
wrapper?: any;
3534
schemas?: any[];
36-
children: (_propsChildren: {
35+
children: FC<{
3736
value: Record<string, any>,
38-
container: IComponentContainer<T>
39-
}) => any;
40-
}) => any
37+
container: FC<IComponentContainerProps<T>>
38+
}>
39+
};
4140
// Record<IVariant, Record<string, Component<any>>>;
4241
// ;
4342
export type IComponents = {
44-
FIELD: Record<string, IComponent<any>>;
45-
VIEW: Record<string, IComponent<any>>;
46-
GROUP: Record<string, IComponentGroup<any>>;
47-
"FIELD-ARRAY": Record<string, IComponentArray<any>>;
48-
"FIELD-OBJECT": Record<string, IComponentObject<any>>;
43+
FIELD: Record<string, FC<IComponentProps<any>>>;
44+
VIEW: Record<string, FC<IComponentProps<any>>>;
45+
GROUP: Record<string, FC<IComponentGroupProps<any>>>;
46+
"FIELD-ARRAY": Record<string, FC<IComponentArrayProps<any>>>;
47+
"FIELD-OBJECT": Record<string, FC<IComponentObjectProps<any>>>;
4948
};
5049

5150
export const ComponentContext = createContext<{ components: IComponents }>({

0 commit comments

Comments
 (0)