Skip to main content
Version: 3.x.x

useListener


import { useListener } from "@hyper-fetch/react"

Description

Defined in react/src/hooks/use-listener/use-listener.hooks.ts:9

Preview

useListener<ListenerType>(listener, options)

Parameters

NameDetails

listener

Required

ListenerType

options

Required

UseListenerOptionsType

Returns

{
connected: boolean;
connecting: boolean;
data: unknown;
listen: () => void;
onClose: (callback: VoidFunction) => void;
onConnecting: (callback: VoidFunction) => void;
onError: (callback: (event: ErrorType) => void) => void;
onEvent: (callback: (data: ExtractListenerAdapterType<ListenerType>, event: MessageEvent<ExtractListenerAdapterType<ListenerType>>) => void) => void;
onOpen: (callback: VoidFunction) => void;
onReconnecting: (callback: (attempts: number) => void) => void;
onReconnectingStop: (callback: (attempts: number) => void) => void;
setConnected: (connected: boolean) => void;
setConnecting: (connecting: boolean) => void;
setData: (data: unknown) => void;
setTimestamp: (timestamp: number) => void;
timestamp: number;
}