mirror of https://github.com/nocodb/nocodb
Browse Source
# What's changed? * extends on VueUses' `createInjectionState` * immediately returns injection state on providepull/2942/head
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