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

useQueuedValue.md

74 lines2.3 KB

1---
2id: useQueuedValue
3title: useQueuedValue
4---
5​
6```ts
7function useQueuedValue<TValue, TSelected>(
8 source,
9 options?,
10 selector?): [Readonly<ShallowRef<TValue>>, VueQueuer<TValue, TSelected>];
11```
12​
13Defined in: [queuer/useQueuedValue.ts:37](https://github.com/TanStack/pacer/blob/main/packages/vue-pacer/src/queuer/useQueuedValue.ts#L37)
14​
15Derives a queued value from its current source.
16​
17Retains accepted items until processing. Ordering, capacity, wait, and started options follow the underlying queue.
18​
19## Return value
20​
21Returns [value, utility]. The value is a readonly shallow ref; read value.value in JavaScript or bind the ref in a template. The source may be a value, a ref, or a getter. The initial value is available immediately. Source changes schedule updates on the existing utility. The exposed value is the last processed item, not the pending item array.
22​
23## State and ownership
24​
25The 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.
26​
27Call during component setup or in an active effect scope. Scope disposal removes watchers and subscriptions and runs utility cleanup.
28Options 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.
29onUnmount replaces default cleanup and receives the utility instance. A custom callback must perform every needed cancel, stop, or abort action.
30​
31## Type Parameters
32​
33### TValue
34​
35`TValue`
36​
37### TSelected
38​
39`TSelected` = \{
40\}
41​
42## Parameters
43​
44### source
45​
46`ValueSource`\<`TValue`\>
47​
48### options?
49​
50[`VuePacerOptions`](../type-aliases/VuePacerOptions.md)\<[`VueQueuerOptions`](../interfaces/VueQueuerOptions.md)\<`TValue`, `TSelected`\>\> = `{}`
51​
52### selector?
53​
54(`state`) => `TSelected`
55​
56## Returns
57​
58\[`Readonly`\<`ShallowRef`\<`TValue`\>\>, [`VueQueuer`](../interfaces/VueQueuer.md)\<`TValue`, `TSelected`\>\]
59​
60## Example
61​
62```ts
63import { ref } from 'vue'
64import { useQueuedValue } from '@tanstack/vue-pacer'
65​
66// During component setup:
67const source = ref('')
68const [value, utility] = useQueuedValue(source, { wait: 500 })
69// Bind value and use utility for controls. Read value.value for the committed value.
70```
71​
72## See
73​
74useQueuer