Skip to content

Commit

Permalink
perf: memo onMouseEnter、onMouseLeave
Browse files Browse the repository at this point in the history
  • Loading branch information
linxianxi committed Dec 20, 2023
1 parent b0b072c commit bdaf038
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/Cell/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,27 @@ function Cell<RecordType>(props: CellProps<RecordType>) {
// ====================== Hover =======================
const [hovering, onHover] = useHoverState(index, mergedRowSpan);

const onMouseEnter: React.MouseEventHandler<HTMLTableCellElement> = event => {
if (record) {
onHover(index, index + mergedRowSpan - 1);
}
const onMouseEnter: React.MouseEventHandler<HTMLTableCellElement> = React.useCallback(
event => {
if (record) {
onHover(index, index + mergedRowSpan - 1);
}

additionalProps?.onMouseEnter?.(event);
};
additionalProps?.onMouseEnter?.(event);
},
[record, onHover, index, mergedRowSpan, additionalProps?.onMouseEnter],
);

const onMouseLeave: React.MouseEventHandler<HTMLTableCellElement> = event => {
if (record) {
onHover(-1, -1);
}
const onMouseLeave: React.MouseEventHandler<HTMLTableCellElement> = React.useCallback(
event => {
if (record) {
onHover(-1, -1);
}

additionalProps?.onMouseLeave?.(event);
};
additionalProps?.onMouseLeave?.(event);
},
[record, onHover, additionalProps?.onMouseLeave],
);

// ====================== Render ======================
if (mergedColSpan === 0 || mergedRowSpan === 0) {
Expand Down

0 comments on commit bdaf038

Please sign in to comment.