Procházet zdrojové kódy

feat: composable useInjection

nian před 1 měsícem
rodič
revize
28189026e6
1 změnil soubory, kde provedl 11 přidání a 0 odebrání
  1. 11 0
      src/composable/useInjection.ts

+ 11 - 0
src/composable/useInjection.ts

@@ -0,0 +1,11 @@
+import { inject } from 'vue'
+
+import type { InjectionKey } from 'vue'
+
+export function useInjection<T>(key: InjectionKey<T> | string) {
+  const context = inject(key, null)
+  if (!context) {
+    throw new Error('useInjection must be used within Injection provider')
+  }
+  return context
+}