diff --git a/src/components/ContextMenu/ContextMenu.tsx b/src/components/ContextMenu/ContextMenu.tsx index f9d125f2c..18368fbb7 100644 --- a/src/components/ContextMenu/ContextMenu.tsx +++ b/src/components/ContextMenu/ContextMenu.tsx @@ -58,12 +58,8 @@ const ContextMenu = ({ children, on, autoClose }: Props) => { }; useEffect(() => { - const containers = on.map((ref) => ref.current).filter((element) => !!element); - containers.forEach((container) => container.addEventListener('contextmenu', onContextMenu)); - - return () => { - containers.forEach((container) => container.removeEventListener('contextmenu', onContextMenu)); - }; + on.forEach((ref) => ref.current && ref.current.addEventListener('contextmenu', onContextMenu)); + return () => on.forEach((ref) => ref.current && ref.current.removeEventListener('contextmenu', onContextMenu)); }, [on]); return active && createPortal((