Skip to content

Commit 6710b54

Browse files
committed
feat: optimize rendering logic in DataTypeInputComponent using React.memo
1 parent ebc575c commit 6710b54

1 file changed

Lines changed: 48 additions & 43 deletions

File tree

src/packages/ce/src/datatype/components/inputs/DataTypeInputComponent.tsx

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -34,48 +34,53 @@ export const DataTypeInputComponent: React.FC<DataTypeInputComponentProps> = (pr
3434
const suggestions = "schema" in (schema ?? {}) ? (schema as NodeSchema)?.schema?.suggestions as (NodeFunction | ReferenceValue | LiteralValue)[] : []
3535
const inputName = "schema" in (schema ?? {}) ? (schema as NodeSchema)?.schema?.input : (schema as Schema)?.input
3636

37-
if ("schema" in (schema ?? {}) && (((schema as NodeSchema).blockedBy?.length ?? 0) > 0) && (rest.formValidation?.valid ?? false)) {
38-
return null
39-
}
37+
return React.useMemo(
38+
() => {
39+
if ("schema" in (schema ?? {}) && (((schema as NodeSchema).blockedBy?.length ?? 0) > 0) && (rest.formValidation?.valid ?? false)) {
40+
return null
41+
}
4042

41-
switch (inputName) {
42-
case "boolean":
43-
return <DataTypeBooleanInputComponent
44-
schema={schema}
45-
suggestions={suggestions}
46-
{...rest}
47-
/>
48-
case "select":
49-
return <DataTypeSelectInputComponent
50-
schema={schema}
51-
suggestions={suggestions}
52-
{...rest}/>
53-
case "number":
54-
return <DataTypeNumberInputComponent
55-
schema={schema}
56-
suggestions={suggestions}
57-
{...rest}/>
58-
case "list":
59-
case "data":
60-
return <DataTypeJSONInputComponent
61-
schema={schema}
62-
suggestions={suggestions}
63-
{...rest}/>
64-
case "generic":
65-
return <DataTypeGenericInputComponent
66-
schema={schema}
67-
suggestions={suggestions}
68-
{...rest}/>
69-
case "sub-flow":
70-
return <DataTypeSubFlowInputComponent
71-
schema={schema}
72-
suggestions={suggestions}
73-
{...rest}/>
74-
default:
75-
return <DataTypeTextInputComponent
76-
suggestions={suggestions}
77-
schema={schema}
78-
{...rest}
79-
/>
80-
}
43+
switch (inputName) {
44+
case "boolean":
45+
return <DataTypeBooleanInputComponent
46+
schema={schema}
47+
suggestions={suggestions}
48+
{...rest}
49+
/>
50+
case "select":
51+
return <DataTypeSelectInputComponent
52+
schema={schema}
53+
suggestions={suggestions}
54+
{...rest}/>
55+
case "number":
56+
return <DataTypeNumberInputComponent
57+
schema={schema}
58+
suggestions={suggestions}
59+
{...rest}/>
60+
case "list":
61+
case "data":
62+
return <DataTypeJSONInputComponent
63+
schema={schema}
64+
suggestions={suggestions}
65+
{...rest}/>
66+
case "generic":
67+
return <DataTypeGenericInputComponent
68+
schema={schema}
69+
suggestions={suggestions}
70+
{...rest}/>
71+
case "sub-flow":
72+
return <DataTypeSubFlowInputComponent
73+
schema={schema}
74+
suggestions={suggestions}
75+
{...rest}/>
76+
default:
77+
return <DataTypeTextInputComponent
78+
suggestions={suggestions}
79+
schema={schema}
80+
{...rest}
81+
/>
82+
}
83+
},
84+
[rest.initialValue, inputName, suggestions?.length ?? 0, rest.formValidation?.valid ?? true, rest.formValidation?.notValidMessage ?? ""]
85+
)
8186
}

0 commit comments

Comments
 (0)