Skip to main content
Version: 5.x.x

useListener


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

Description

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

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: (response: [object Object]) => 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;
}