Skip to content

Commit 8889777

Browse files
author
刘欢
committed
feat: add callback to getPrefixCls
1 parent 8eaa8b6 commit 8889777

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/components/config-provider/config-provider.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,17 @@ export const ConfigProvider: FC<ConfigProviderProps> = props => {
8181
const { children, ...config } = props
8282
const parentConfig = useConfig()
8383

84-
const getPrefixCls = (suffixCls?: string, customizePrefixCls?: string) => {
85-
if (customizePrefixCls) {
86-
return customizePrefixCls
87-
}
88-
const mergedPrefixCls =
89-
config.prefixCls || parentConfig.prefixCls || defaultPrefixCls
90-
return suffixCls ? `${mergedPrefixCls}-${suffixCls}` : mergedPrefixCls
91-
}
84+
const getPrefixCls = React.useCallback(
85+
(suffixCls?: string, customizePrefixCls?: string) => {
86+
if (customizePrefixCls) {
87+
return customizePrefixCls
88+
}
89+
const mergedPrefixCls =
90+
config.prefixCls || parentConfig.prefixCls || defaultPrefixCls
91+
return suffixCls ? `${mergedPrefixCls}-${suffixCls}` : mergedPrefixCls
92+
},
93+
[config.prefixCls, parentConfig.prefixCls]
94+
)
9295

9396
return (
9497
<ConfigContext.Provider

0 commit comments

Comments
 (0)