Skip to content

Function: useInjection()

ts
function useInjection<T>(injectionId: ServiceIdentifier<T>): T;

Defined in: src/wirestate-react/injection/use-injection.ts:32

Resolves a service or constant from the active container.

Type Parameters

Type ParameterDescription
TThe type of the value being resolved.

Parameters

ParameterTypeDescription
injectionIdServiceIdentifier<T>The service identifier (string, symbol, or constructor).

Returns

T

The resolved instance or value.

Remarks

This hook re-resolves the dependency when the active container or token changes.

Throws

If the container is not found in context.

Throws

If Inversify fails to resolve the identifier.

Example

tsx
const api: ApiService = useInjection(ApiService);