createWebSocketTopics
Manage reference-counted topic subscriptions that are sent again after every reconnect.
Available from both react-websocket and react-websocket/core.
Usage
Hold topics from components with useWebSocketTopic. The guide is Topic subscriptions.
Parameters
Returns
WebSocketTopics:
Behavior
- Shared. The first
acquireof a topic sendssubscribeif the socket is open. Otherwise it's sent on open. More holders send nothing. - Deferred unsubscribe. A tick after the last release,
unsubscribeis sent, unless the topic was acquired again in the meantime. - Reconnects. On every open, every held topic is subscribed on the new socket, before the client flushes its send queue.
- Never queued. Subscription messages bypass the send queue, so nothing is sent twice.
- Requires TypeScript 5.4+ for the inferred message types (it uses
NoInfer).