Network
Two hooks for long-lived network connections — both wrap a browser connection object opened for a given URL and torn down on unmount or when the URL changes.
useWebSocket
WebSocket connection state ("connecting" | "open" | "closed") plus send()/close(), wrapping a WebSocket opened for url and torn down on unmount or when url changes. Pass undefined to stay disconnected (e.g. before an auth token is ready).
const { status, lastMessage, send } = useWebSocket("wss://example.com");
if (status === "open") send("ping");useEventSource
Server-Sent Events connection state ("connecting" | "open" | "closed") plus the latest message event's data, wrapping an EventSource (part of the Server-sent events spec) opened for url and torn down on unmount or when url changes. Pass undefined to stay disconnected.
const { status, data } = useEventSource("https://example.com/stream");