UNPKG

react-eventsource-hook

Version:

⚠️ DEPRECATED: Use 'react-eventsource' instead. React hook for Server-Sent Events with custom headers support, built on @microsoft/fetch-event-source

21 lines (18 loc) 687 B
import { EventSourceMessage } from '@microsoft/fetch-event-source'; interface UseEventSourceOptions { url: string; headers?: Record<string, string>; method?: string; body?: string | FormData; onMessage?: (message: EventSourceMessage) => void; onOpen?: (response: Response) => void; onError?: (error: unknown) => void; fetch?: typeof window.fetch; } interface UseEventSourceResult { readyState: number; close: () => void; reconnect: () => void; } declare function useEventSource(options: UseEventSourceOptions): UseEventSourceResult; export { type UseEventSourceOptions, type UseEventSourceResult, useEventSource, useEventSource as useSSE };