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