From dc590ca3e6ac8c9db9aa4572a85cf1b2d746a9c1 Mon Sep 17 00:00:00 2001 From: xiamiao Date: Fri, 28 Jun 2024 10:48:44 +0800 Subject: [PATCH] =?UTF-8?q?feat(descriptions):=20=E5=8E=BB=E6=8E=89?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/ui/descriptions/src/Descriptions.tsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/ui/descriptions/src/Descriptions.tsx b/packages/ui/descriptions/src/Descriptions.tsx index a957e4661..3abb70c99 100644 --- a/packages/ui/descriptions/src/Descriptions.tsx +++ b/packages/ui/descriptions/src/Descriptions.tsx @@ -13,6 +13,8 @@ import { DescriptionsItem, DescriptionsItemProps } from './DescriptionsItem' const DESCRIPTIONS_PREFIX = getPrefixCls('descriptions') +const DEFAULT_DATA = [] as [] + /** * 描述列表组件 */ @@ -23,7 +25,7 @@ export const Descriptions = forwardRef role = 'descriptions', className, children, - data, + data = DEFAULT_DATA, fieldNames, column = 3, placement = 'horizontal', @@ -40,10 +42,7 @@ export const Descriptions = forwardRef const vertical = placement === 'vertical' const bordered = appearance === 'table' || noBackground - const transformedData = useMemo(() => { - if (data) return transformData(data, fieldNames) - else return data - }, [data, fieldNames]) + const transformedData = useMemo(() => transformData(data, fieldNames), [data, fieldNames]) // 如果配置了data,则使用配置模式渲染,否则取 children const computeChildren = transformedData ? computeItems(transformedData)