Skip to content

Commit 4960fa9

Browse files
wanpan11afc163
andauthored
perf: Optimize expandIcon rerender (#746)
* perf: Optimize expandIcon rerender * Update src/SubMenu/index.tsx Co-authored-by: afc163 <[email protected]> * perf: update * perf: update --------- Co-authored-by: afc163 <[email protected]>
1 parent f94aec3 commit 4960fa9

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/SubMenu/index.tsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,23 @@ const InternalSubMenu = React.forwardRef<HTMLLIElement, SubMenuProps>(
227227
// =============================== Render ===============================
228228
const popupId = domDataId && `${domDataId}-popup`;
229229

230+
const expandIconNode = React.useMemo(
231+
() => (
232+
<Icon
233+
icon={mode !== 'horizontal' ? mergedExpandIcon : undefined}
234+
props={{
235+
...props,
236+
isOpen: open,
237+
// [Legacy] Not sure why need this mark
238+
isSubMenu: true,
239+
}}
240+
>
241+
<i className={`${subMenuPrefixCls}-arrow`} />
242+
</Icon>
243+
),
244+
[mode, mergedExpandIcon, props, open, subMenuPrefixCls],
245+
);
246+
230247
// >>>>> Title
231248
let titleNode: React.ReactElement = (
232249
<div
@@ -248,17 +265,7 @@ const InternalSubMenu = React.forwardRef<HTMLLIElement, SubMenuProps>(
248265
{title}
249266

250267
{/* Only non-horizontal mode shows the icon */}
251-
<Icon
252-
icon={mode !== 'horizontal' ? mergedExpandIcon : undefined}
253-
props={{
254-
...props,
255-
isOpen: open,
256-
// [Legacy] Not sure why need this mark
257-
isSubMenu: true,
258-
}}
259-
>
260-
<i className={`${subMenuPrefixCls}-arrow`} />
261-
</Icon>
268+
{expandIconNode}
262269
</div>
263270
);
264271

0 commit comments

Comments
 (0)