add console.log
This commit is contained in:
parent
4569251b14
commit
0a2a0128ef
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user