Hooks

useWebSocket

Publisher

cermuel

50 hooks published

More from this publisher

useWebSocket

Manage connections, reconnecting, and messages.

useWebSocket.tsx
import { useWebSocket } from "@cermuel/hooks/react";export function useWebSocketExample() {  const socket = useWebSocket("wss://example.com");  return <p>{socket.status}</p>;}

Props

Param
Type
Default Value
url
string
options?
WebSocketOptions
{}

Returns

{ status: WebSocketStatus; messages: MessageEvent<any>[]; send: (data: string | ArrayBufferLike | Blob | ArrayBufferView) => void | undefined; close: () => void | undefined; connect: () => void; }