type: code optimization (#50116)

This commit is contained in:
lijianan 2024-07-29 01:31:25 +08:00 committed by GitHub
parent 525e33737d
commit 836d1bbbad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 39 deletions

View File

@ -3,11 +3,7 @@ import LeftOutlined from '@ant-design/icons/LeftOutlined';
import LoadingOutlined from '@ant-design/icons/LoadingOutlined';
import RightOutlined from '@ant-design/icons/RightOutlined';
export default function useColumnIcons(
prefixCls: string,
rtl: boolean,
expandIcon?: React.ReactNode,
) {
const useColumnIcons = (prefixCls: string, rtl: boolean, expandIcon?: React.ReactNode) => {
let mergedExpandIcon = expandIcon;
if (!expandIcon) {
mergedExpandIcon = rtl ? <LeftOutlined /> : <RightOutlined />;
@ -19,5 +15,10 @@ export default function useColumnIcons(
</span>
);
return [mergedExpandIcon, loadingIcon];
}
return React.useMemo<Readonly<[React.ReactNode, React.ReactNode]>>(
() => [mergedExpandIcon, loadingIcon] as const,
[mergedExpandIcon],
);
};
export default useColumnIcons;

View File

@ -1,22 +1,14 @@
import { useContext } from 'react';
import { genStyleUtils } from '@ant-design/cssinjs-utils';
import type { GetCompUnitless } from '@ant-design/cssinjs-utils/es/util/genStyleUtils';
import { ConfigContext } from '../../config-provider/context';
import { genCommonStyle, genLinkStyle } from '../../style';
import type {
AliasToken,
ComponentTokenMap,
SeedToken,
} from '../interface';
import localUseToken, { unitless } from '../useToken';
import type { AliasToken, ComponentTokenMap, SeedToken } from '../interface';
import useLocalToken, { unitless } from '../useToken';
import useResetIconStyle from './useResetIconStyle';
export const {
genStyleHooks,
genComponentStyleHook,
genSubStyleComponent,
} = genStyleUtils<
export const { genStyleHooks, genComponentStyleHook, genSubStyleComponent } = genStyleUtils<
ComponentTokenMap,
AliasToken,
SeedToken
@ -29,18 +21,11 @@ export const {
return {
rootPrefixCls,
iconPrefixCls,
}
};
},
useToken: () => {
const [theme, realToken, hashId, token, cssVar] = localUseToken();
return {
theme,
realToken,
hashId,
token,
cssVar,
};
const [theme, realToken, hashId, token, cssVar] = useLocalToken();
return { theme, realToken, hashId, token, cssVar };
},
useCSP: () => {
const { csp, iconPrefixCls } = useContext(ConfigContext);
@ -50,14 +35,7 @@ export const {
return csp ?? {};
},
getResetStyles: (token) =>
[
{
// Link
'&': genLinkStyle(token),
},
]
,
getResetStyles: (token) => [{ '&': genLinkStyle(token) }],
getCommonStyle: genCommonStyle,
getCompUnitless: () => unitless as any,
})
getCompUnitless: (() => unitless) as GetCompUnitless<ComponentTokenMap, AliasToken>,
});