Skip to content

Commit 71b2cd4

Browse files
committed
fix: use ref
1 parent 3c42cb9 commit 71b2cd4

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/compass-context-menu/src/context-menu-provider.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import React, {
55
useMemo,
66
createContext,
77
useContext,
8+
useRef,
89
} from 'react';
910

1011
import type {
@@ -47,6 +48,9 @@ export function ContextMenuProvider({
4748
[setMenu]
4849
);
4950

51+
const onContextMenuOpenRef = useRef(onContextMenuOpen);
52+
onContextMenuOpenRef.current = onContextMenuOpen;
53+
5054
const handleClosingEvent = useCallback(
5155
(event: Event) => {
5256
if (!event.defaultPrevented) {
@@ -69,7 +73,7 @@ export function ContextMenuProvider({
6973
return;
7074
}
7175

72-
onContextMenuOpen?.(itemGroups);
76+
onContextMenuOpenRef.current?.(itemGroups);
7377

7478
setMenu({
7579
isOpen: true,
@@ -92,8 +96,7 @@ export function ContextMenuProvider({
9296
capture: true,
9397
});
9498
};
95-
// eslint-disable-next-line react-hooks/exhaustive-deps
96-
}, [disabled, handleClosingEvent, parentContext]);
99+
}, [disabled, handleClosingEvent, onContextMenuOpenRef, parentContext]);
97100

98101
const value = useMemo(
99102
() => ({

0 commit comments

Comments
 (0)