add console.log

This commit is contained in:
Nastya 2025-03-26 18:01:03 +03:00
parent 4569251b14
commit 0a2a0128ef
2 changed files with 5 additions and 2 deletions

@ -3,12 +3,13 @@ import ReconnectingEventSource from "reconnecting-eventsource";
import { devlog } from "../utils";
export function useSSESubscription<T>({ enabled = true, url, onNewData, onDisconnect, marker = "" }: {
export function useSSESubscription<T>({ 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<T>({ 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) {

@ -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",