diff --git a/lib/hooks/useSSESubscription.ts b/lib/hooks/useSSESubscription.ts index ba72415..2a515e3 100644 --- a/lib/hooks/useSSESubscription.ts +++ b/lib/hooks/useSSESubscription.ts @@ -3,12 +3,13 @@ import ReconnectingEventSource from "reconnecting-eventsource"; import { devlog } from "../utils"; -export function useSSESubscription({ enabled = true, url, onNewData, onDisconnect, marker = "" }: { +export function useSSESubscription({ enabled = true, url, onNewData, onDisconnect, marker = "", consolelog = false }: { enabled?: boolean; url: string; onNewData: (data: T[]) => void; onDisconnect?: () => void; marker?: string; + consolelog?: boolean; }) { const onNewDataRef = useRef(onNewData); const onDisconnectRef = useRef(onDisconnect); @@ -27,7 +28,9 @@ export function useSSESubscription({ enabled = true, url, onNewData, onDiscon eventSource.addEventListener("close", () => devlog(`EventSource closed with ${url}`)); eventSource.addEventListener("message", event => { try { + if (consolelog) console.log(event); const newData = JSON.parse(event.data) as T; + if (newData) console.log(event.data); devlog(`new SSE: ${marker}`, newData); onNewDataRef.current([newData]); } catch (error) { diff --git a/package.json b/package.json index f8a61a0..3734f98 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@frontend/kitui", - "version": "2.0.1", + "version": "2.0.2", "description": "test", "main": "./dist/index.js", "module": "./dist/index.js",