( composable: (...args: Arguments) => Return, options?: CreateInjectionStateOptions<Return>, )
| 20 | * |
| 21 | */ |
| 22 | export function createInjectionState<Arguments extends Array<any>, Return>( |
| 23 | composable: (...args: Arguments) => Return, |
| 24 | options?: CreateInjectionStateOptions<Return>, |
| 25 | ): readonly [useProvidingState: (...args: Arguments) => Return, useInjectedState: () => Return | undefined] { |
| 26 | const key: string | InjectionKey<Return> = options?.injectionKey || Symbol(composable.name || 'InjectionState') |
| 27 | const defaultValue = options?.defaultValue |
| 28 | const useProvidingState = (...args: Arguments) => { |
| 29 | const state = composable(...args) |
| 30 | provideLocal(key, state) |
| 31 | return state |
| 32 | } |
| 33 | const useInjectedState = () => injectLocal(key, defaultValue) |
| 34 | return [useProvidingState, useInjectedState] |
| 35 | } |
no outgoing calls
no test coverage detected