(config: EffectConfig<TRow, TKey>, deps: React.DependencyList = [])
| 28 | * ``` |
| 29 | */ |
| 30 | export 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 | } |
no test coverage detected
searching dependent graphs…