Skip to content

Commit 2c27f85

Browse files
committed
refactor: 去掉memo
1 parent 359f3b2 commit 2c27f85

File tree

4 files changed

+54
-81
lines changed

4 files changed

+54
-81
lines changed

src/components/ButtonIcon.tsx

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -36,48 +36,45 @@ const computeClass = (className: string) => {
3636

3737
/** - 生成复用的button */
3838

39-
const ButtonIcon: FC<Props> = memo(
40-
({
41-
children,
42-
className = 'h-36px text-icon',
43-
icon,
44-
style,
45-
tooltipContent,
46-
tooltipPlacement = 'bottom',
47-
triggerParent,
48-
zIndex = 98,
49-
...rest
50-
}) => {
51-
const cls = computeClass(className);
39+
const ButtonIcon = ({
40+
children,
41+
className = 'h-36px text-icon',
42+
icon,
43+
style,
44+
tooltipContent,
45+
tooltipPlacement = 'bottom',
46+
triggerParent,
47+
zIndex = 98,
48+
...rest
49+
}: Props) => {
50+
const cls = computeClass(className);
5251

53-
function getPopupContainer(triggerNode: HTMLElement) {
54-
return triggerParent ? triggerNode.parentElement! : document.body;
55-
}
56-
57-
return (
58-
<ATooltip
59-
getPopupContainer={getPopupContainer}
60-
placement={tooltipPlacement}
61-
title={tooltipContent}
62-
zIndex={zIndex}
63-
>
64-
<AButton
65-
className={cls}
66-
type="text"
67-
{...rest}
68-
>
69-
<div className="flex-center gap-8px">
70-
{children || (
71-
<SvgIcon
72-
icon={icon}
73-
style={style}
74-
/>
75-
)}
76-
</div>
77-
</AButton>
78-
</ATooltip>
79-
);
52+
function getPopupContainer(triggerNode: HTMLElement) {
53+
return triggerParent ? triggerNode.parentElement! : document.body;
8054
}
81-
);
8255

56+
return (
57+
<ATooltip
58+
getPopupContainer={getPopupContainer}
59+
placement={tooltipPlacement}
60+
title={tooltipContent}
61+
zIndex={zIndex}
62+
>
63+
<AButton
64+
className={cls}
65+
type="text"
66+
{...rest}
67+
>
68+
<div className="flex-center gap-8px">
69+
{children || (
70+
<SvgIcon
71+
icon={icon}
72+
style={style}
73+
/>
74+
)}
75+
</div>
76+
</AButton>
77+
</ATooltip>
78+
);
79+
};
8380
export default ButtonIcon;

src/components/SvgIcon.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { Icon } from '@iconify/react';
22
import type { CSSProperties } from 'react';
3-
/**
4-
* Props
5-
*
6-
* - Support iconify and local svg icon
7-
* - If icon and localIcon are passed at the same time, localIcon will be rendered first
8-
*/
3+
94
interface Props {
105
readonly className?: string;
116
/** Iconify icon name */
@@ -16,12 +11,21 @@ interface Props {
1611
}
1712

1813
const defaultLocalIcon = 'no-icon';
14+
1915
const { VITE_ICON_LOCAL_PREFIX: prefix } = import.meta.env;
16+
2017
const symbolId = (localIcon: string = defaultLocalIcon) => {
2118
const iconName = localIcon || defaultLocalIcon;
2219

2320
return `#${prefix}-${iconName}`;
2421
};
22+
23+
/**
24+
* Props
25+
*
26+
* - Support iconify and local svg icon
27+
* - If icon and localIcon are passed at the same time, localIcon will be rendered first
28+
*/
2529
const SvgIcon = ({ icon, localIcon, ...props }: Props) => {
2630
/** If localIcon is passed, render localIcon first */
2731
return localIcon || !icon ? (

src/components/SystemLogo.tsx

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,7 @@
1-
import * as motion from 'motion/react-m';
1+
import type { SVGProps } from 'react';
22

3-
const SystemLogo = memo((props: { className?: string }) => {
4-
const [hideStroke, { setTrue }] = useBoolean();
5-
6-
const draw = {
7-
animate: { fill: 'currentColor', pathLength: 1 },
8-
fill: 'transparent',
9-
initial: { fill: 'transparent', pathLength: 0 },
10-
stroke: hideStroke ? 'none' : 'currentColor',
11-
strokeWidth: '2',
12-
transition: {
13-
fill: { delay: 2, duration: 1, ease: 'easeInOut' },
14-
pathLength: { duration: 2, ease: 'easeInOut' }
15-
}
16-
};
17-
return (
18-
<motion.svg
19-
viewBox="0 0 160 160"
20-
{...props}
21-
>
22-
<motion.path
23-
{...draw}
24-
d="M81.28 55.9c-.1-11.67-2.93-22.55-9.37-32.38-1-1.5-2.14-2.86-2.5-4.71a8.1 8.1 0 014-8.61 7.89 7.89 0 019.3 1.23 35.999 35.999 0 015.9 8.83 75.18 75.18 0 018.44 28.58 83.211 83.211 0 01-5.23 36.74 102.983 102.983 0 01-3 7.28 1.2 1.2 0 000 1.41c9.58 13.3 21.76 23 37.85 27.24a54.37 54.37 0 0019.68 1.57 7.72 7.72 0 018.36 6.9 7.903 7.903 0 01-6.7 9 64.744 64.744 0 01-23-1.33 77.68 77.68 0 01-36.93-19.88 93.628 93.628 0 01-11.91-13.71 2.18 2.18 0 00-2.3-1.06 72.744 72.744 0 00-27.38 7.55c-11.6 6-20.67 14.58-26.4 26.45a10.134 10.134 0 01-3.7 4.7 8 8 0 01-9.19-.7 7.86 7.86 0 01-2.36-9.28 60.324 60.324 0 018.72-14.52c12.2-15.43 28.21-24.59 47.32-28.57A85.085 85.085 0 0173.07 87c.524.015 1-.307 1.18-.8a76.06 76.06 0 006.53-22.3c.351-2.652.518-5.325.5-8z"
25-
/>
26-
<motion.path
27-
{...draw}
28-
d="M136.26 108.34a44.742 44.742 0 01-11.13-2.87 46.108 46.108 0 01-19.66-13.76 8 8 0 015.72-13.22 7.93 7.93 0 016.54 2.93 33.27 33.27 0 0018.87 10.75c1.546.155 3.058.553 4.48 1.18a8.08 8.08 0 013.84 9.21c-.92 3.52-4.13 5.81-8.66 5.78zm-80.6-75.02a7.61 7.61 0 016.64 5 49.139 49.139 0 013.64 17 46.33 46.33 0 01-2.46 17.28c-2 5.77-8.24 7.79-12.89 4.15a8.1 8.1 0 01-2.39-9 31.679 31.679 0 001.68-12.36 35.77 35.77 0 00-2.43-11c-2.1-5.45 1.75-11.07 8.21-11.07zm22.26 93.25a8 8 0 01-6.68 7.86 32.88 32.88 0 00-19.7 12.19 8.13 8.13 0 01-11.21 1.62 8 8 0 01-1.41-11.58A51.043 51.043 0 0154 123.81a45.842 45.842 0 0114-5.1c5.35-1.04 9.91 2.56 9.92 7.86z"
29-
onAnimationComplete={setTrue}
30-
/>
31-
</motion.svg>
32-
);
33-
});
3+
const SystemLogo = (props: SVGProps<SVGSVGElement>) => {
4+
return <IconLocalLogo {...props} />;
5+
};
346

357
export default SystemLogo;

src/components/WaveBg.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ interface Props {
55
themeColor: string;
66
}
77

8-
const WaveBg = memo(({ themeColor }: Props) => {
8+
const WaveBg = ({ themeColor }: Props) => {
99
const lightColor = getPaletteColorByNumber(themeColor, 200);
1010
const darkColor = getPaletteColorByNumber(themeColor, 500);
1111

@@ -93,6 +93,6 @@ const WaveBg = memo(({ themeColor }: Props) => {
9393
</div>
9494
</div>
9595
);
96-
});
96+
};
9797

9898
export default WaveBg;

0 commit comments

Comments
 (0)