Skip to content

consumeContext

consumeContext<T>(host, context, onChange?): ContextConsumption<T>

Defined in: packages/webcomponents/src/consumeContext.js:29

Subscribe to a context value on a host element using the framework-agnostic Context Protocol.

Unlike @lit/context’s ContextConsumer, this needs no ReactiveControllerHost — it works on a bare HTMLElement, so a plain custom element can consume a block/config provided by any protocol-speaking ancestor (Lit or otherwise). The onChange callback fires synchronously on request() if a provider answers, and again whenever a subscribed provider’s value changes.

T

HTMLElement

The element that dispatches the request.

The context key to request.

T

(value) => void

Called with each new value.

ContextConsumption<T>