MCPcopy Create free account
hub / github.com/cn-docs/vueuse / createInjectionState

Function createInjectionState

packages/shared/createInjectionState/index.ts:22–35  ·  view source on GitHub ↗
(
  composable: (...args: Arguments) => Return,
  options?: CreateInjectionStateOptions<Return>,
)

Source from the content-addressed store, hash-verified

20 *
21 */
22export 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}

Callers 2

index.test.tsFile · 0.90
useCounterStore.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected