Skip to main content
Version: 3.x.x

useEmitter


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

Description

Defined in react/src/hooks/use-emitter/use-emitter.hooks.ts:8

Preview

useEmitter<EmitterType>(emitter, options)

Parameters

NameDetails

emitter

Required

EmitterType

options

Required

UseEmitterOptionsType

Returns

{
connected: boolean;
connecting: boolean;
emit: (options?: Partial<EmitterCloneOptionsType<any, any>>, ack?: (error: Error, response: any) => void) => string;
onClose: (callback: VoidFunction) => void;
onConnecting: (callback: VoidFunction) => void;
onError: (callback: (event: ErrorType) => void) => void;
onEvent: (callback: (emitter: EmitterType) => void) => void;
onOpen: (callback: VoidFunction) => void;
onReconnecting: (callback: (attempts: number) => void) => void;
onReconnectingStop: (callback: (attempts: number) => void) => void;
reconnect: number;
setConnected: (connected: boolean) => void;
setConnecting: (connecting: boolean) => void;
setData: (data: unknown) => void;
setTimestamp: (timestamp: number) => void;
timestamp: number;
}