UNPKG

@react-nano/use-event-source

Version:

A lightweight EventSource (server-sent-events) hook for react, written in TypeScript

11 lines (10 loc) 579 B
type EventSourceConstructor = { new (url: string, eventSourceInitDict?: EventSourceInit): EventSource; }; export type EventSourceStatus = "init" | "open" | "closed" | "error"; export type EventSourceEvent = Event & { data: string; }; export declare function useEventSource(url: string, withCredentials?: boolean, ESClass?: EventSourceConstructor): readonly [EventSource | null, EventSourceStatus]; export declare function useEventSourceListener(source: EventSource | null, types: string[], listener: (e: EventSourceEvent) => void, dependencies?: any[]): void; export {};