Skip to main content
Version: 2.x.x

useListener


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

Description

Defined in hooks/use-listener/use-listener.hooks.ts:8

Preview

useListener<ListenerType>(listener, __namedParameters)

Parameters

NameDetails

listener

Required

ListenerType

__namedParameters

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: ExtractListenerDataType<ListenerType>, event: MessageEvent<ExtractListenerDataType<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;
}