Web Sockets | useWeb (original) (raw)
This functions provides simple websocket client capabilities.
# State
The useWebSocket
function exposes the following reactive state:
State | Type | Description |
---|---|---|
state | Ref | The current websocket state, can be only one of: 'OPEN', 'CONNECTING', 'CLOSING', 'CLOSED' |
data | Ref | Reference to the latest data received via the websocket, can be watched to respond to incoming messages |
# Methods
useWebSocket
exposes the following methods:
Method | Signature | Description |
---|---|---|
send | (data: any) => void | Sends data through the websocket connection. |
close | (code?: number, reason?: string) => void | Closes the websocket connection gracefully. |
# Example
# Demo
TODO: Cool Chat app maybe