소스 검색

feat: composable useInjection

nian 1 개월 전
부모
커밋
28189026e6
1개의 변경된 파일11개의 추가작업 그리고 0개의 파일을 삭제
  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
+}