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 Parameter | Description |
|---|---|
T | The type of the value being resolved. |
Parameters
| Parameter | Type | Description |
|---|---|---|
injectionId | ServiceIdentifier<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);