Function: useContainerProvision()
ts
function useContainerProvision<E>(host: E, options: ContainerProviderOptions): ContainerProvider<E>;Defined in: src/wirestate-lit/provision/use-container-provision.ts:52
Hook that provides a container to the host element and its children.
Type Parameters
| Type Parameter |
|---|
E extends ReactiveControllerHost & HTMLElement |
Parameters
| Parameter | Type | Description |
|---|---|---|
host | E | The host element. |
options | ContainerProviderOptions | Provisioning options. |
Returns
An instance of ContainerProvider.
Remarks
Pass container to expose an external Container without taking ownership. Pass config to create a managed container when the host connects, run provider lifecycle hooks while connected, destroy it on disconnect, and recreate it on reconnect.
The container value is published through Lit context only while the host is connected. Before the first connection and after disconnection, the provider value is undefined.
Examples
typescript
class MyRootElement extends LitElement {
private containerProvider: ContainerProvider = useContainerProvision(this, {
config: {
entries: [LoggerService],
activate: [LoggerService],
},
});
}typescript
class MyRootElement extends LitElement {
private containerProvider: ContainerProvider = useContainerProvision(this, { container: container });
}