Open History to see the last commit
1---
2id: throttleStrategy
3title: throttleStrategy
4---
5
6# Function: throttleStrategy()
7
8```ts
9function throttleStrategy(options): ThrottleStrategy;
10```
11
12Defined in: [packages/db/src/strategies/throttleStrategy.ts:48](https://github.com/TanStack/db/blob/main/packages/db/src/strategies/throttleStrategy.ts#L48)
13
14Creates a throttle strategy that ensures transactions are evenly spaced
15over time.
16
17Provides smooth, controlled execution patterns ideal for UI updates like
18sliders, progress bars, or scroll handlers where you want consistent
19execution timing.
20
21## Parameters
22
23### options
24
25[`ThrottleStrategyOptions`](../interfaces/ThrottleStrategyOptions.md)
26
27Configuration for throttle behavior
28
29## Returns
30
31[`ThrottleStrategy`](../interfaces/ThrottleStrategy.md)
32
33A throttle strategy instance
34
35## Examples
36
37```ts
38// Throttle slider updates to every 200ms
39const mutate = usePacedMutations({
40 onMutate: (volume) => {
41 settingsCollection.update('volume', draft => { draft.value = volume })
42 },
43 mutationFn: async ({ transaction }) => {
44 await api.updateVolume(transaction.mutations)
45 },
46 strategy: throttleStrategy({ wait: 200 })
47})
48```
49
50```ts
51// Throttle with leading and trailing execution
52const mutate = usePacedMutations({
53 onMutate: (data) => {
54 collection.update(id, draft => { Object.assign(draft, data) })
55 },
56 mutationFn: async ({ transaction }) => {
57 await api.save(transaction.mutations)
58 },
59 strategy: throttleStrategy({
60 wait: 500,
61 leading: true,
62 trailing: true
63 })
64})
65```