From 6292e8b53c10d8ff350ea020fd5fd5baaa548046 Mon Sep 17 00:00:00 2001 From: "xinhui.zxh" Date: Wed, 13 Jan 2021 17:05:05 +0800 Subject: [PATCH] feat: use rc-util's useMemo for config provider --- components/config-provider/index.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/components/config-provider/index.tsx b/components/config-provider/index.tsx index 5f839b29a0..1f62a34be0 100644 --- a/components/config-provider/index.tsx +++ b/components/config-provider/index.tsx @@ -1,6 +1,7 @@ import * as React from 'react'; import { FormProvider as RcFormProvider } from 'rc-field-form'; import { ValidateMessages } from 'rc-field-form/lib/interface'; +import useMemo from 'rc-util/lib/hooks/useMemo'; import { RenderEmptyHandler } from './renderEmpty'; import LocaleProvider, { Locale, ANT_MARK } from '../locale-provider'; import LocaleReceiver from '../locale-provider/LocaleReceiver'; @@ -151,9 +152,17 @@ const ProviderChildren: React.FC = props => { const config = getConfig(); // https://github.com/ant-design/ant-design/issues/27617 - const memoedConfig = React.useMemo( + const memoedConfig = useMemo( () => config, - configConsumerProps.map(k => (config as Record)[k]), + config, + (prevConfig: Record, currentConfig) => { + const prevKeys = Object.keys(prevConfig); + const currentKeys = Object.keys(currentConfig); + return ( + prevKeys.length !== currentKeys.length || + prevKeys.some(key => prevConfig[key] !== currentConfig[key]) + ); + }, ); let childNode = children;