fn
injectWithApp
v0.1.0testeddemoDrop-in replacement for inject that also works outside of component setup.
Inside an injection context it behaves exactly like inject (component-level provides
win); outside it resolves app-level provides through the active app. When no app is
available it falls back to the provided default value, or throws if there is none.
Example
ts
const theme = injectWithApp(ThemeKey, 'light');Demo
Loading demo…
Signatures
ts
export function injectWithApp<Value>(key: InjectionKey<Value> | string): Value | undefined;ts
export function injectWithApp<Value>(key: InjectionKey<Value> | string, defaultValue: Value, treatDefaultAsFactory?: false): Value;ts
export function injectWithApp<Value>(key: InjectionKey<Value> | string, defaultValue: Value | (() => Value), treatDefaultAsFactory: true): Value;Type Parameters
ValueParameters
| Parameter | Type | Description |
|---|---|---|
key | InjectionKey<Value> | string | The injection key |
defaults? | InjectDefaults<Value> | — |
Returns
Value | undefinedThe injected value