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

ReactAsyncQueuer.md

98 lines2.2 KB

1---
2id: ReactAsyncQueuer
3title: ReactAsyncQueuer
4---
5​
6Defined in: [async-queuer/useAsyncQueuer.ts:23](https://github.com/TanStack/pacer/blob/main/packages/react-pacer/src/async-queuer/useAsyncQueuer.ts#L23)
7​
8## Extends
9​
10- `Omit`\<`AsyncQueuer`\<`TValue`\>, `"store"`\>
11​
12## Type Parameters
13​
14### TValue
15​
16`TValue`
17​
18### TSelected
19​
20`TSelected` = \{
21\}
22​
23## Properties
24​
25### state
26​
27```ts
28readonly state: Readonly<TSelected>;
29```
30​
31Defined in: [async-queuer/useAsyncQueuer.ts:49](https://github.com/TanStack/pacer/blob/main/packages/react-pacer/src/async-queuer/useAsyncQueuer.ts#L49)
32​
33Reactive state that will be updated and re-rendered when the queuer state changes
34​
35Use this instead of `queuer.store.state`
36​
37***
38​
39### ~~store~~
40​
41```ts
42readonly store: Store<Readonly<AsyncQueuerState<TValue>>>;
43```
44​
45Defined in: [async-queuer/useAsyncQueuer.ts:55](https://github.com/TanStack/pacer/blob/main/packages/react-pacer/src/async-queuer/useAsyncQueuer.ts#L55)
46​
47#### Deprecated
48​
49Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state.
50The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
51Although, you can make the state reactive by using the `useSelector` in your own usage.
52​
53***
54​
55### Subscribe
56​
57```ts
58Subscribe: <TSelected>(props) => ReactNode | Promise<ReactNode>;
59```
60​
61Defined in: [async-queuer/useAsyncQueuer.ts:40](https://github.com/TanStack/pacer/blob/main/packages/react-pacer/src/async-queuer/useAsyncQueuer.ts#L40)
62​
63A React HOC (Higher Order Component) that allows you to subscribe to the queuer state.
64​
65This is useful for opting into state re-renders for specific parts of the queuer state
66deep in your component tree without needing to pass a selector to the hook.
67​
68#### Type Parameters
69​
70##### TSelected
71​
72`TSelected`
73​
74#### Parameters
75​
76##### props
77​
78###### children
79​
80`ReactNode` \| ((`state`) => `ReactNode`)
81​
82###### selector
83​
84(`state`) => `TSelected`
85​
86#### Returns
87​
88`ReactNode` \| `Promise`\<`ReactNode`\>
89​
90#### Example
91​
92```ts
93<queuer.Subscribe selector={(state) => ({ size: state.size, isRunning: state.isRunning })}>
94 {({ size, isRunning }) => (
95 <div>Queue: {size} items, {isRunning ? 'Processing' : 'Idle'}</div>
96 )}
97</queuer.Subscribe>
98```