Function: useInjection()
ts
function useInjection<T>(host: ReactiveControllerHost & HTMLElement, optionsOrInjectionId:
| UseInjectionOptions<T>
| ServiceIdentifier<T>): UseInjectionValue<T>;Defined in: src/wirestate-lit/consumption/use-injection.ts:82
Consumes a service from the nearest Lit container context.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
host | ReactiveControllerHost & HTMLElement | Host element. |
optionsOrInjectionId | | UseInjectionOptions<T> | ServiceIdentifier<T> | Service token or options. |
Returns
Mutable injection holder.
Examples
typescript
class MyElement extends LitElement {
private myService = useInjection(this, MyService);
render() {
return html`<div>${this.myService.value.getName()}</div>`;
}
}typescript
class MyElement extends LitElement {
private myService = useInjection(this, { injectionId: MyService, once: true });
render() {
return html`<div>${this.myService.value.getName()}</div>`;
}
}