Open History to see the last commit
1---
2id: createQueuedState
3title: createQueuedState
4---
5
6```ts
7function createQueuedState<TValue, TSelected>(
8 scope,
9 fn,
10 options?,
11 selector?): [() => TValue[], (item, position?, runOnItemsChange?) => boolean, AlpineQueuer<TValue, TSelected>];
12```
13
14Defined in: [queuer/createQueuedState.ts:35](https://github.com/TanStack/pacer/blob/main/packages/alpine-pacer/src/queuer/createQueuedState.ts#L35)
15
16Exposes pending queue items together with the queue that processes them.
17
18Retains accepted items until processing. Ordering, capacity, wait, and started options follow the underlying queue.
19
20## Return value
21
22Returns [itemsAccessor, addItem, queue]. Call itemsAccessor() to read pending items.
23
24## State and ownership
25
26Items 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.
27
28Pass the owning PacerScope first, or call the method on that scope. Destroy the scope in the Alpine component's destroy method.
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` *extends* `Pick`\<`QueuerState`\<`TValue`\>, `"items"`\> = `Pick`\<`QueuerState`\<`TValue`\>, `"items"`\>
41
42## Parameters
43
44### scope
45
46[`PacerScope`](../interfaces/PacerScope.md)
47
48### fn
49
50(`item`) => `void`
51
52### options?
53
54[`AlpinePacerOptions`](../type-aliases/AlpinePacerOptions.md)\<[`AlpineQueuerOptions`](../interfaces/AlpineQueuerOptions.md)\<`TValue`, `TSelected`\>\> = `{}`
55
56### selector?
57
58(`state`) => `TSelected`
59
60## Returns
61
62\[() => `TValue`[], (`item`, `position?`, `runOnItemsChange?`) => `boolean`, [`AlpineQueuer`](../interfaces/AlpineQueuer.md)\<`TValue`, `TSelected`\>\]
63
64## Example
65
66```ts
67import { createQueuedState } from '@tanstack/alpine-pacer'
68
69// scope belongs to the current Alpine component.
70const [items, addItem, queue] = createQueuedState(scope, (item: number) => { console.log(item) }, { wait: 500 })
71addItem(1)
72console.log(items())
73```
74
75## See
76
77createQueuer