MCPcopy Index your code
hub / github.com/TanStack/db / useLiveQueryEffect

Function useLiveQueryEffect

packages/react-db/src/useLiveQueryEffect.ts:30–59  ·  view source on GitHub ↗
(config: EffectConfig<TRow, TKey>, deps: React.DependencyList = [])

Source from the content-addressed store, hash-verified

28 * ```
29 */
30export function useLiveQueryEffect<
31 TRow extends object = Record<string, unknown>,
32 TKey extends string | number = string | number,
33>(config: EffectConfig<TRow, TKey>, deps: React.DependencyList = []): void {
34 const configRef = useRef<EffectConfig<TRow, TKey>>(config)
35 configRef.current = config
36
37 useEffect(() => {
38 const effect: Effect = createEffect<TRow, TKey>({
39 id: config.id,
40 query: config.query,
41 skipInitial: config.skipInitial,
42 onEnter: (event, ctx) => configRef.current.onEnter?.(event, ctx),
43 onUpdate: (event, ctx) => configRef.current.onUpdate?.(event, ctx),
44 onExit: (event, ctx) => configRef.current.onExit?.(event, ctx),
45 onBatch: (events, ctx) => configRef.current.onBatch?.(events, ctx),
46 onError: config.onError
47 ? (error, event) => configRef.current.onError?.(error, event)
48 : undefined,
49 onSourceError: config.onSourceError
50 ? (error) => configRef.current.onSourceError?.(error)
51 : undefined,
52 })
53
54 return () => {
55 // Fire-and-forget disposal; AbortSignal cancels in-flight work
56 effect.dispose()
57 }
58 }, deps)
59}

Callers 1

Calls 2

createEffectFunction · 0.90
disposeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…