From 3da6bdc65964de26d772d11b02c3c116d1a0fb70 Mon Sep 17 00:00:00 2001 From: dream2023 <1098626505@qq.com> Date: Mon, 22 Jan 2024 21:22:33 +0800 Subject: [PATCH] fix: withDynamicSchemaProps --- .../application/hoc/withDynamicSchemaProps.tsx | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/core/client/src/application/hoc/withDynamicSchemaProps.tsx b/packages/core/client/src/application/hoc/withDynamicSchemaProps.tsx index dbf1750fcf..bb0c60eb05 100644 --- a/packages/core/client/src/application/hoc/withDynamicSchemaProps.tsx +++ b/packages/core/client/src/application/hoc/withDynamicSchemaProps.tsx @@ -11,14 +11,20 @@ interface WithSchemaHookOptions { export function withDynamicSchemaProps(Component: ComponentType, options: WithSchemaHookOptions = {}) { const displayName = options.displayName || Component.displayName || Component.name; const ComponentWithProps: ComponentType = (props) => { - const { dn } = useDesignable(); + const { dn, findComponent } = useDesignable(); const { scope } = useSchemaComponentContext(); const useComponentPropsStr = useMemo(() => { - if (dn.getSchemaAttribute('x-component')) { - return dn.getSchemaAttribute('x-use-component-props'); + const xComponent = dn.getSchemaAttribute('x-component'); + const xDecorator = dn.getSchemaAttribute('x-decorator'); + const xUseComponentProps = dn.getSchemaAttribute('x-use-component-props'); + const xUseDecoratorProps = dn.getSchemaAttribute('x-use-decorator-props'); + + if (xComponent && xUseComponentProps && findComponent(xComponent) === ComponentWithProps) { + return xUseComponentProps; } - if (dn.getSchemaAttribute('x-decorator')) { - return dn.getSchemaAttribute('x-use-decorator-props'); + + if (xDecorator && xUseDecoratorProps && findComponent(xDecorator) === ComponentWithProps) { + return xUseDecoratorProps; } }, [dn]); const useSchemaProps = useMemo(() => {