Skip to content

lit-ui-router / requestContext

Variable: requestContext ​

ts
const requestContext: <T>(target, key, options?) => ContextType<T> | undefined;

Defined in: packages/lit-ui-router/src/context.ts:264

Requests key from whichever provider answers on target, and returns the value a provider supplied synchronously.

The target is any EventTarget, not only an element. Returns undefined when nobody answered. Every answer reaches options.callback; the return value is the first one only.

Type Parameters ​

Type ParameterDescription
T extends UnknownContextthe context key's type, branded with the value it references

Parameters ​

ParameterTypeDescription
targetEventTargetthe event target to dispatch the request from
keyTthe context key to request, matched by identity
options?RequestContextOptions<T>subscription and callback options

Returns ​

ContextType<T> | undefined

Example ​

ts
import { requestContext, routerContext } from 'lit-ui-router/context';

const router = requestContext(element, routerContext);