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

ReactAsyncDebouncer.md

98 lines2.2 KB

1---
2id: ReactAsyncDebouncer
3title: ReactAsyncDebouncer
4---
5​
6Defined in: [async-debouncer/useAsyncDebouncer.ts:24](https://github.com/TanStack/pacer/blob/main/packages/react-pacer/src/async-debouncer/useAsyncDebouncer.ts#L24)
7​
8## Extends
9​
10- `Omit`\<`AsyncDebouncer`\<`TFn`\>, `"store"`\>
11​
12## Type Parameters
13​
14### TFn
15​
16`TFn` *extends* `AnyAsyncFunction`
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-debouncer/useAsyncDebouncer.ts:50](https://github.com/TanStack/pacer/blob/main/packages/react-pacer/src/async-debouncer/useAsyncDebouncer.ts#L50)
32​
33Reactive state that will be updated and re-rendered when the debouncer state changes
34​
35Use this instead of `debouncer.store.state`
36​
37***
38​
39### ~~store~~
40​
41```ts
42readonly store: Store<Readonly<AsyncDebouncerState<TFn>>>;
43```
44​
45Defined in: [async-debouncer/useAsyncDebouncer.ts:56](https://github.com/TanStack/pacer/blob/main/packages/react-pacer/src/async-debouncer/useAsyncDebouncer.ts#L56)
46​
47#### Deprecated
48​
49Use `debouncer.state` instead of `debouncer.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-debouncer/useAsyncDebouncer.ts:41](https://github.com/TanStack/pacer/blob/main/packages/react-pacer/src/async-debouncer/useAsyncDebouncer.ts#L41)
62​
63A React HOC (Higher Order Component) that allows you to subscribe to the debouncer state.
64​
65This is useful for opting into state re-renders for specific parts of the debouncer 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<debouncer.Subscribe selector={(state) => ({ isExecuting: state.isExecuting })}>
94 {({ isExecuting }) => (
95 <div>{isExecuting ? 'Loading...' : 'Ready'}</div>
96 )}
97</debouncer.Subscribe>
98```