Open History to see the last commit
1---
2id: useLiveQueryEffect
3title: useLiveQueryEffect
4---
5
6# Function: useLiveQueryEffect()
7
8```ts
9function useLiveQueryEffect<TRow, TKey>(config, deps): void;
10```
11
12Defined in: [useLiveQueryEffect.ts:30](https://github.com/TanStack/db/blob/main/packages/react-db/src/useLiveQueryEffect.ts#L30)
13
14React hook for creating a reactive effect that fires handlers when rows
15enter, exit, or update within a query result.
16
17The effect is created on mount and disposed on unmount. If `deps` change,
18the previous effect is disposed and a new one is created.
19
20## Type Parameters
21
22### TRow
23
24`TRow` *extends* `object` = `Record`\<`string`, `unknown`\>
25
26### TKey
27
28`TKey` *extends* `string` \| `number` = `string` \| `number`
29
30## Parameters
31
32### config
33
34`EffectConfig`\<`TRow`, `TKey`\>
35
36### deps
37
38`DependencyList` = `[]`
39
40## Returns
41
42`void`
43
44## Example
45
46```tsx
47function ChatComponent() {
48 useLiveQueryEffect(
49 {
50 query: (q) => q.from({ msg: messages }).where(({ msg }) => eq(msg.role, 'user')),
51 skipInitial: true,
52 onEnter: async (event) => {
53 await generateResponse(event.value)
54 },
55 },
56 []
57 )
58
59 return <div>...</div>
60}
61```