useWebSocketEvent
Listen to a client's events without re-rendering the component.
Usage
Parameters
Behavior
- No re-renders. The hook never causes a render itself. Your listener decides whether to update state.
- Latest listener. The listener always sees the latest props and state. Changing it doesn't resubscribe or reconnect.
- Holds the connection. While mounted, the component keeps the client connected, just like
useWebSocket. - One subscription per call. Call the hook once per event type you need.
Tips
- Combine it with
useWebSocketStatusfor a component that shows status and handles messages, without re-rendering per message. - For very high message rates, buffer messages in a ref and flush them to state once per animation frame. See Performance.