UNPKG

@tanstack/react-db

Version:

React integration for @tanstack/db

27 lines (26 loc) 993 B
import { useRef, useEffect } from "react"; import { createEffect } from "@tanstack/db"; function useLiveQueryEffect(config, deps = []) { const configRef = useRef(config); configRef.current = config; useEffect(() => { const effect = createEffect({ id: config.id, query: config.query, skipInitial: config.skipInitial, onEnter: (event, ctx) => configRef.current.onEnter?.(event, ctx), onUpdate: (event, ctx) => configRef.current.onUpdate?.(event, ctx), onExit: (event, ctx) => configRef.current.onExit?.(event, ctx), onBatch: (events, ctx) => configRef.current.onBatch?.(events, ctx), onError: config.onError ? (error, event) => configRef.current.onError?.(error, event) : void 0, onSourceError: config.onSourceError ? (error) => configRef.current.onSourceError?.(error) : void 0 }); return () => { effect.dispose(); }; }, deps); } export { useLiveQueryEffect }; //# sourceMappingURL=useLiveQueryEffect.js.map