Skip to content

Function: useContainer()

ts
function useContainer<E>(host: E): UseContainerValue;

Defined in: src/wirestate-lit/consumption/use-container.ts:47

Consumes the active container from the nearest Lit context.

Type Parameters

Type Parameter
E extends ReactiveControllerHost & HTMLElement

Parameters

ParameterTypeDescription
hostEHost element.

Returns

UseContainerValue

Container holder that resolves to the active container.

Remarks

The returned value updates when the nearest provided container changes. Reading value before the context resolves (no container provider above the host) throws.

Example

typescript
import { LitElement, html } from "lit";

class MyElement extends LitElement {
  private container: UseContainerValue = useContainer(this);

  public render() {
    return html`<div>${this.container.value.has(MyService)}</div>`;
  }
}