Skip to content

Commit

Permalink
perf: memo onMouseEnter、onMouseLeave (#1061)
Browse files Browse the repository at this point in the history
* perf: memo onMouseEnter、onMouseLeave

* chore: useCallback -> useEvent
  • Loading branch information
linxianxi authored Dec 21, 2023
1 parent b0b072c commit 3128690
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Cell/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
} from '../interface';
import useCellRender from './useCellRender';
import useHoverState from './useHoverState';
import { useEvent } from 'rc-util';

export interface CellProps<RecordType extends DefaultRecordType> {
prefixCls?: string;
Expand Down Expand Up @@ -153,21 +154,21 @@ function Cell<RecordType>(props: CellProps<RecordType>) {
// ====================== Hover =======================
const [hovering, onHover] = useHoverState(index, mergedRowSpan);

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

additionalProps?.onMouseEnter?.(event);
};
});

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

additionalProps?.onMouseLeave?.(event);
};
});

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

1 comment on commit 3128690

@vercel
Copy link

@vercel vercel bot commented on 3128690 Dec 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

table – ./

table-react-component.vercel.app
table-git-master-react-component.vercel.app

Please sign in to comment.