Skip to content

Commit

Permalink
perf(tree): code perf
Browse files Browse the repository at this point in the history
  • Loading branch information
HaixingOoO committed Dec 23, 2024
1 parent 84bf0d3 commit c10fdaa
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/tree/hooks/useTreeVirtualScroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import useVirtualScroll from '../../hooks/useVirtualScroll';
import TreeNode from '../../_common/js/tree-v1/tree-node';
import { TScroll } from '../../common';
import type { TdTreeProps } from '../type';
import useEventCallback from '../../hooks/useEventCallback';

export default function useTreeVirtualScroll({
treeRef,
Expand Down Expand Up @@ -48,7 +49,7 @@ export default function useTreeVirtualScroll({
});

let lastScrollY = -1;
const onInnerVirtualScroll = (e: WheelEvent) => {
const onInnerVirtualScroll = useEventCallback((e: WheelEvent) => {
onScroll?.({ e });
if (!isVirtual) {
return;
Expand All @@ -62,7 +63,7 @@ export default function useTreeVirtualScroll({
lastScrollY = -1;
}
lastScrollY = top;
};
});

useEffect(() => {
const treeList = treeRef?.current;
Expand All @@ -72,8 +73,7 @@ export default function useTreeVirtualScroll({
// 卸载时取消监听
treeList?.removeEventListener?.('scroll', onInnerVirtualScroll);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [onInnerVirtualScroll]);
}, [treeRef, onInnerVirtualScroll]);

const cursorStyle = {
position: 'absolute',
Expand Down

0 comments on commit c10fdaa

Please sign in to comment.