Open History to see the last commit
1---
2id: createRateLimitedValue
3title: createRateLimitedValue
4---
5
6```ts
7function createRateLimitedValue<TValue, TSelected>(
8 host,
9 source,
10 options,
11 selector?): [CellValue<TValue>, LitRateLimiter<SetValue<TValue>, TSelected>];
12```
13
14Defined in: [rate-limiter/createRateLimitedValue.ts:37](https://github.com/TanStack/pacer/blob/main/packages/lit-pacer/src/rate-limiter/createRateLimitedValue.ts#L37)
15
16Derives a rate-limited value from its current source.
17
18Accepts updates while the configured limit has capacity in its fixed or sliding window. Rejected updates are discarded instead of delayed.
19
20## Return value
21
22Returns [value, utility]. The value is an accessor; call value() from render(). Pass a getter that reads reactive source state. The initial value is available immediately. Source changes schedule updates on the existing utility.
23
24## State and ownership
25
26The value updates independently of the utility selector. The default utility selection is {}. Pass a selector to subscribe to fields such as executionCount, isPending, or status where the underlying utility exposes them.
27
28Pass the owning ReactiveControllerHost first. Host updates refresh options. Disconnecting runs cleanup; reconnecting restores subscriptions to the same utility.
29Options accept an object with top-level getters or an options factory. Function-valued core options remain callbacks. Local options override provider defaults without replacing the utility or its pending work.
30onUnmount replaces default cleanup and receives the utility instance. A custom callback must perform every needed cancel, stop, or abort action.
31
32## Type Parameters
33
34### TValue
35
36`TValue`
37
38### TSelected
39
40`TSelected` = \{
41\}
42
43## Parameters
44
45### host
46
47`ReactiveControllerHost`
48
49### source
50
51`ValueSource`\<`TValue`\>
52
53### options
54
55[`LitPacerOptions`](../type-aliases/LitPacerOptions.md)\<[`LitRateLimiterOptions`](../interfaces/LitRateLimiterOptions.md)\<`SetValue`\<`TValue`\>, `TSelected`\>\>
56
57### selector?
58
59(`state`) => `TSelected`
60
61## Returns
62
63\[`CellValue`\<`TValue`\>, [`LitRateLimiter`](../interfaces/LitRateLimiter.md)\<`SetValue`\<`TValue`\>, `TSelected`\>\]
64
65## Example
66
67```ts
68import { createRateLimitedValue } from '@tanstack/lit-pacer'
69
70// In a LitElement constructor:
71// query is a reactive property on this host.
72const [value, utility] = createRateLimitedValue(this, () => this.query, { limit: 3, window: 1000 })
73// Bind value and use utility for controls. Read value() for the committed value.
74```
75
76## See
77
78createRateLimiter