From 9684e55f1a610df1e61a4eb4550cbd668cb0a213 Mon Sep 17 00:00:00 2001 From: chenos Date: Tue, 25 Jan 2022 09:21:41 +0800 Subject: [PATCH] feat: memoized schema component --- .../components/SchemaComponent.tsx | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/packages/client/src/schema-component/components/SchemaComponent.tsx b/packages/client/src/schema-component/components/SchemaComponent.tsx index e448364bc..576a66411 100644 --- a/packages/client/src/schema-component/components/SchemaComponent.tsx +++ b/packages/client/src/schema-component/components/SchemaComponent.tsx @@ -18,13 +18,29 @@ function toSchema(schema?: any) { return new Schema(schema); } -export function SchemaComponent(props: ISchemaFieldProps) { +const useMemoizedSchema = (schema) => { + return useMemo(() => toSchema(schema), []); +}; + +const RecursionSchemaComponent = (props: ISchemaFieldProps) => { const { components, scope, schema, ...others } = props; - const s = useMemo(() => toSchema(schema), []); - console.log('SchemaComponent', { components, scope }); return ( - + ); -} +}; + +const MemoizedSchemaComponent = (props: ISchemaFieldProps) => { + const { schema, ...others } = props; + const s = useMemoizedSchema(schema); + return ; +}; + +export const SchemaComponent = (props: ISchemaFieldProps & { memoized?: boolean }) => { + const { memoized, ...others } = props; + if (memoized) { + return ; + } + return ; +};