mirror of https://github.com/nocodb/nocodb
Pranav C
2 years ago
committed by
GitHub
2 changed files with 20 additions and 0 deletions
@ -0,0 +1,19 @@
|
||||
import type { InjectionKey } from 'vue' |
||||
|
||||
export function useInjectionState<Arguments extends any[], Return>( |
||||
composable: (...args: Arguments) => Return, |
||||
): readonly [useProvidingState: (...args: Arguments) => void, useInjectedState: () => Return | undefined] { |
||||
const key: string | InjectionKey<Return> = Symbol('InjectionState') |
||||
|
||||
const useProvidingState = (...args: Arguments) => { |
||||
const providedState = composable(...args) |
||||
|
||||
provide(key, providedState) |
||||
|
||||
return providedState |
||||
} |
||||
|
||||
const useInjectedState = () => inject(key) |
||||
|
||||
return [useProvidingState, useInjectedState] |
||||
} |
Loading…
Reference in new issue