about summary refs log tree commit diff
path: root/src/components/ContextMenu/context.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/ContextMenu/context.tsx')
-rw-r--r--src/components/ContextMenu/context.tsx31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/components/ContextMenu/context.tsx b/src/components/ContextMenu/context.tsx
new file mode 100644
index 000000000..213d87a8c
--- /dev/null
+++ b/src/components/ContextMenu/context.tsx
@@ -0,0 +1,31 @@
+import React from 'react'
+
+import type {ContextType, ItemContextType} from '#/components/ContextMenu/types'
+
+export const Context = React.createContext<ContextType | null>(null)
+
+export const ItemContext = React.createContext<ItemContextType | null>(null)
+
+export function useContextMenuContext() {
+  const context = React.useContext(Context)
+
+  if (!context) {
+    throw new Error(
+      'useContextMenuContext must be used within a Context.Provider',
+    )
+  }
+
+  return context
+}
+
+export function useContextMenuItemContext() {
+  const context = React.useContext(ItemContext)
+
+  if (!context) {
+    throw new Error(
+      'useContextMenuItemContext must be used within a Context.Provider',
+    )
+  }
+
+  return context
+}