Skip to main content
This hook requires the OrderbookProvider to be present in your component tree.

Import

import { useOrderbookStatus } from '@krono/hooks'

Usage

import { useOrderbookStatus } from '@krono/hooks'

function ConnectionStatusBadge() {
  const status = useOrderbookStatus();

  return (
    <div className={`badge badge-${status}`}>
      Status: {status}
    </div>
  );
}

Return Type

Returns a ConnectionStatus string literal:
status
'disconnected' | 'connecting' | 'connected' | 'error'
  • disconnected: The socket is idle or manually closed
  • connecting: A connection or subscription is in progress
  • reconnecting: Reconnect after connection closed
  • connected: The socket is open and actively receiving heartbeat/data
  • error: The connection failed or encountered an error

Examples

Blocking UI during Connection

Use the status to prevent user interaction while the orderbook is initializing.
function TradingButton() {
  const status = useOrderbookStatus();
  const ready = status === 'connected';

  return (
    <button disabled={!ready}>
      {ready ? 'Place Order' : 'Waiting for connection...'}
    </button>
  );
}