From f7ce6c9fb0e1062ef7c24fbb038fb9f6e9492952 Mon Sep 17 00:00:00 2001 From: Tanimodori Date: Tue, 17 Jan 2023 17:22:21 +0800 Subject: [PATCH] feat(createInjectionState): return state when providing injection state (#2309) * feat: return state when providing injection state * Update packages/shared/createInjectionState/index.ts Co-authored-by: lsdsjy Co-authored-by: lsdsjy --- packages/shared/createInjectionState/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/shared/createInjectionState/index.ts b/packages/shared/createInjectionState/index.ts index 2428cd300b9..41e10551f31 100644 --- a/packages/shared/createInjectionState/index.ts +++ b/packages/shared/createInjectionState/index.ts @@ -8,10 +8,12 @@ import { type InjectionKey, inject, provide } from 'vue-demi' */ export function createInjectionState, Return>( composable: (...args: Arguments) => Return, -): readonly [useProvidingState: (...args: Arguments) => void, useInjectedState: () => Return | undefined] { +): readonly [useProvidingState: (...args: Arguments) => Return, useInjectedState: () => Return | undefined] { const key: string | InjectionKey = Symbol('InjectionState') const useProvidingState = (...args: Arguments) => { - provide(key, composable(...args)) + const state = composable(...args) + provide(key, state) + return state } const useInjectedState = () => inject(key) return [useProvidingState, useInjectedState]