File tree Expand file tree Collapse file tree 1 file changed +8
-13
lines changed Expand file tree Collapse file tree 1 file changed +8
-13
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,13 @@ export function ContextMenuProvider({
24
24
// Check if there's already a parent context menu provider
25
25
const parentContext = useContext ( Context ) ;
26
26
27
+ // Prevent accidental nested providers
28
+ if ( parentContext ) {
29
+ throw new Error (
30
+ 'Duplicated ContextMenuProvider found. Please remove the nested provider.'
31
+ ) ;
32
+ }
33
+
27
34
const [ menu , setMenu ] = useState < ContextMenuState > ( {
28
35
isOpen : false ,
29
36
itemGroups : [ ] ,
@@ -41,11 +48,6 @@ export function ContextMenuProvider({
41
48
) ;
42
49
43
50
useEffect ( ( ) => {
44
- // If there's a parent provider, don't add event listeners
45
- if ( parentContext ) {
46
- return ;
47
- }
48
-
49
51
function handleContextMenu ( event : MouseEvent ) {
50
52
event . preventDefault ( ) ;
51
53
@@ -73,7 +75,7 @@ export function ContextMenuProvider({
73
75
document . removeEventListener ( 'contextmenu' , handleContextMenu ) ;
74
76
window . removeEventListener ( 'resize' , handleClosingEvent ) ;
75
77
} ;
76
- } , [ handleClosingEvent , parentContext ] ) ;
78
+ } , [ handleClosingEvent ] ) ;
77
79
78
80
const value = useMemo (
79
81
( ) => ( {
@@ -82,13 +84,6 @@ export function ContextMenuProvider({
82
84
[ close ]
83
85
) ;
84
86
85
- // Prevent accidental nested providers
86
- if ( parentContext ) {
87
- throw new Error (
88
- 'Duplicated ContextMenuProvider found. Please remove the nested provider.'
89
- ) ;
90
- }
91
-
92
87
const Wrapper = wrapper ?? React . Fragment ;
93
88
94
89
return (
You can’t perform that action at this time.
0 commit comments