v2.0.2 add console.log

This commit is contained in:
Nastya 2025-05-10 23:36:42 +03:00
parent 7ce1904cb5
commit 24fa6510ad
2 changed files with 4 additions and 3 deletions

@ -3,12 +3,12 @@ import ReconnectingEventSource from "reconnecting-eventsource";
import { devlog } from "../utils";
export function useSSESubscription<T>({ enabled = true, url, onNewData, onDisconnect, marker = "" }: {
enabled?: boolean;
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,6 +27,7 @@ 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;
devlog(`new SSE: ${marker}`, newData);
onNewDataRef.current([newData]);

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