Skip to content

useEventSource ​

browser
test coverage
Last changed: 6 days ago

TIP

This hook uses EventSource browser api to provide enhanced functionality. Make sure to check for compatibility with different browsers when using this api

Hook that provides a reactive wrapper for event source

typescript
import { useEventSource } from '@siberiacancode/reactuse';

Usage ​

typescript
const { instance, data, isConnecting, isOpen, isError, close, open } = useEventSource('url', ['message']);

Demo ​

Api ​

Parameters

NameTypeDefaultNote
urlstring | URL-The URL of the EventSource
events?string[][]List of events to listen to
options?UseEventSourceOptions{}Configuration options

Source ​

Source • Demo

Contributors ​

Avatardebabin
Avatarnailgilmanov

Released under the MIT License.