Skip to content
Source
Sign inSign up
TanStack/pacer
Open History to see the last commit

ThrottlerOptions.md

119 lines2.4 KB

1---
2id: ThrottlerOptions
3title: ThrottlerOptions
4---
5​
6Defined in: [throttler.ts:54](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/throttler.ts#L54)
7​
8Options for configuring a throttled function
9​
10## Type Parameters
11​
12### TFn
13​
14`TFn` *extends* [`AnyFunction`](../type-aliases/AnyFunction.md)
15​
16## Properties
17​
18### enabled?
19​
20```ts
21optional enabled?: boolean | ((throttler) => boolean);
22```
23​
24Defined in: [throttler.ts:60](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/throttler.ts#L60)
25​
26Whether the throttler is enabled. When disabled, maybeExecute will not trigger any executions.
27Can be a boolean or a function that returns a boolean.
28Defaults to true.
29​
30***
31​
32### initialState?
33​
34```ts
35optional initialState?: Partial<ThrottlerState<TFn>>;
36```
37​
38Defined in: [throttler.ts:64](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/throttler.ts#L64)
39​
40Initial state for the throttler
41​
42***
43​
44### key?
45​
46```ts
47optional key?: string;
48```
49​
50Defined in: [throttler.ts:69](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/throttler.ts#L69)
51​
52A key to identify the throttler.
53If provided, the throttler will be identified by this key in the devtools and PacerProvider if applicable.
54​
55***
56​
57### leading?
58​
59```ts
60optional leading?: boolean;
61```
62​
63Defined in: [throttler.ts:74](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/throttler.ts#L74)
64​
65Whether to execute on the leading edge of the timeout.
66Defaults to true.
67​
68***
69​
70### onExecute?
71​
72```ts
73optional onExecute?: (args, throttler) => void;
74```
75​
76Defined in: [throttler.ts:78](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/throttler.ts#L78)
77​
78Callback function that is called after the function is executed
79​
80#### Parameters
81​
82##### args
83​
84`Parameters`\<`TFn`\>
85​
86##### throttler
87​
88[`Throttler`](../classes/Throttler.md)\<`TFn`\>
89​
90#### Returns
91​
92`void`
93​
94***
95​
96### trailing?
97​
98```ts
99optional trailing?: boolean;
100```
101​
102Defined in: [throttler.ts:83](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/throttler.ts#L83)
103​
104Whether to execute on the trailing edge of the timeout.
105Defaults to true.
106​
107***
108​
109### wait
110​
111```ts
112wait: number | ((throttler) => number);
113```
114​
115Defined in: [throttler.ts:89](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/throttler.ts#L89)
116​
117Time window in milliseconds during which the function can only be executed once.
118Can be a number or a function that returns a number.
119Defaults to 0ms