---
url: https://lit-ui-router.dev/reference/lit-ui-router/core/requestContext.md
---
[lit-ui-router](../index.md) / requestContext

# Variable: requestContext

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

Defined in: [packages/lit-ui-router/src/context.ts:269](https://github.com/simshanith/lit-ui-router/blob/740888c2b2ba358c4dfa52a122e927df6a604b12/packages/lit-ui-router/src/context.ts#L269)

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](../types/RequestContextOptions.md#callback); the return value
is the first one only.

## Type Parameters

| Type Parameter | Description |
| ------ | ------ |
|  `T` *extends* [`UnknownContext`](../types/UnknownContext.md) | the context key's type, branded with the value it references |

## Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `target` | `EventTarget` | the event target to dispatch the request from |
| `key` | `T` | the context key to request, matched by identity |
| `options?` | [`RequestContextOptions`](../types/RequestContextOptions.md)<`T`> | subscription and callback options |

## Returns

[`ContextType`](../types/ContextType.md)<`T`> | `undefined`

## Example

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

declare const element: HTMLElement;

const router = requestContext(element, routerContext);
```
