Skip to content

Commit 8bd8d2b

Browse files
committed
fix(useDoubleClick): take re-renders into account, therefore memo the clickCounmt
1 parent 660bc9a commit 8bd8d2b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/table/Row/useDoubleClick.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@ const useDoubleClickBase = ({
1414
onSingleClick: (e: Event) => void;
1515
onDoubleClick: ((e: Event) => void) | null;
1616
}) => {
17+
const clickCount = React.useRef(0);
18+
1719
React.useEffect(() => {
1820
const { current } = ref;
1921

20-
let clickCount = 0;
21-
2222
const handleDoubleClick = (event: any) => {
2323
if (onDoubleClick) {
24-
if (clickCount === 0) {
24+
if (clickCount.current === 0) {
2525
onSingleClick(event);
2626
}
2727

28-
clickCount += 1;
28+
clickCount.current += 1;
2929

3030
setTimeout(() => {
31-
if (clickCount === 2) onDoubleClick(event);
31+
if (clickCount.current === 2) onDoubleClick(event);
3232

33-
clickCount = 0;
33+
clickCount.current = 0;
3434
}, 300);
3535
}
3636
};

0 commit comments

Comments
 (0)