From 749f03e424543db90ea2af82b3e17cef3a6b7bd9 Mon Sep 17 00:00:00 2001 From: "xinhui.zxh" Date: Wed, 13 Jan 2021 13:02:56 +0800 Subject: [PATCH] feat: use useCallback for getPrefixCls --- components/config-provider/index.tsx | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/components/config-provider/index.tsx b/components/config-provider/index.tsx index 3c90925c9a..5f839b29a0 100644 --- a/components/config-provider/index.tsx +++ b/components/config-provider/index.tsx @@ -96,22 +96,18 @@ const ProviderChildren: React.FC = props => { parentContext, } = props; - const getPrefixClsWrapper = (context: ConfigConsumerProps) => ( - suffixCls: string, - customizePrefixCls?: string, - ) => { - const { prefixCls } = props; + const getPrefixCls = React.useCallback( + (suffixCls: string, customizePrefixCls?: string) => { + const { prefixCls } = props; - if (customizePrefixCls) return customizePrefixCls; + if (customizePrefixCls) return customizePrefixCls; - const mergedPrefixCls = prefixCls || context.getPrefixCls(''); + const mergedPrefixCls = prefixCls || parentContext.getPrefixCls(''); - return suffixCls ? `${mergedPrefixCls}-${suffixCls}` : mergedPrefixCls; - }; - - const getPrefixCls = React.useMemo(() => getPrefixClsWrapper(parentContext), [ - parentContext.getPrefixCls, - ]); + return suffixCls ? `${mergedPrefixCls}-${suffixCls}` : mergedPrefixCls; + }, + [parentContext.getPrefixCls], + ); const getConfig = (): ConfigConsumerProps => { const config = { @@ -156,7 +152,7 @@ const ProviderChildren: React.FC = props => { // https://github.com/ant-design/ant-design/issues/27617 const memoedConfig = React.useMemo( - () => getConfig(), + () => config, configConsumerProps.map(k => (config as Record)[k]), );