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

useQueuedState.md

72 lines2.2 KB

1---
2id: useQueuedState
3title: useQueuedState
4---
5​
6```ts
7function useQueuedState<TValue, TSelected>(
8 fn,
9 options?,
10 selector?): [() => TValue[], (item, position?, runOnItemsChange?) => boolean, VueQueuer<TValue, TSelected>];
11```
12​
13Defined in: [queuer/useQueuedState.ts:34](https://github.com/TanStack/pacer/blob/main/packages/vue-pacer/src/queuer/useQueuedState.ts#L34)
14​
15Exposes pending queue items together with the queue that processes them.
16​
17Retains accepted items until processing. Ordering, capacity, wait, and started options follow the underlying queue.
18​
19## Return value
20​
21Returns [itemsAccessor, addItem, queue]. Call itemsAccessor() to read pending items.
22​
23## State and ownership
24​
25Items are selected by default. A custom selector must retain items and may add other state fields. The returned collection contains pending items; async active items are separate.
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` *extends* `Pick`\<`QueuerState`\<`TValue`\>, `"items"`\> = `Pick`\<`QueuerState`\<`TValue`\>, `"items"`\>
40​
41## Parameters
42​
43### fn
44​
45(`item`) => `void`
46​
47### options?
48​
49[`VuePacerOptions`](../type-aliases/VuePacerOptions.md)\<[`VueQueuerOptions`](../interfaces/VueQueuerOptions.md)\<`TValue`, `TSelected`\>\> = `{}`
50​
51### selector?
52​
53(`state`) => `TSelected`
54​
55## Returns
56​
57\[() => `TValue`[], (`item`, `position?`, `runOnItemsChange?`) => `boolean`, [`VueQueuer`](../interfaces/VueQueuer.md)\<`TValue`, `TSelected`\>\]
58​
59## Example
60​
61```ts
62import { useQueuedState } from '@tanstack/vue-pacer'
63​
64// During component setup:
65const [items, addItem, queue] = useQueuedState((item: number) => { console.log(item) }, { wait: 500 })
66addItem(1)
67console.log(items())
68```
69​
70## See
71​
72useQueuer