useWebSocketLatency
Read round-trip time and server clock offset from createWebSocketLatency.
Usage
Parameters
Returns
Latency: { rtt, offset }, both in ms, both undefined until the first pong.
Behavior
- Renders. It re-renders when a measurement changes, about once per ping interval.
- Connection. It holds the client connection while mounted, like the other hooks.
- Server rendering. On the server and during hydration, both values are
undefined. - Server time. For the server's clock, call
latency.serverNow()where you need it, such as in a timer or animation frame, instead of renderingoffset.