NetworkConnection

Shows whether the client is connected. Set status yourself (connected, connecting, disconnected or error) to drive it from a socket or an API health check; add details, latency and an onRetry action.

Freeze ray
Connectedfreeze.gru-lair.example42 ms
Banana server
Connecting
Shrink ray
Connection error503 Service Unavailable

Detecting the connection. Leave status out and it checks the browser: the online and offline events, and, with a probeUrl, whether the internet can really be reached (a small request, repeated every interval ms and when the browser comes back online), so a Wi-Fi network without internet shows as "Connected, no internet access" and not as online. showConnectionInfo adds the connection type and speed where the browser reports them, and onStatusChange tells you about changes. variant is panel, a small badge, or a banner that appears only while something is wrong. The same logic is available as the useNetworkStatus hook.

Lair connection
Online
OnlineLast change: none yet
Online

As a banner. variant="banner" shows a bar only while the connection is down, so put it under your AppBar (className="sticky top-0 z-50" keeps it in view). The check runs when the page loads, when the browser reports it is back online, every interval ms and when someone presses Retry, so recovery shows within a moment.

Not sure how to see it? The Playground section for NetworkConnection has a ? button at the top right of each example that explains four ways to test it, and the Simulate buttons below show each state without touching your network.

Online

Page content. In Detect mode the banner stays hidden while you are online: switch your network off to see it.

Props

  • status'connected' | 'connecting' | 'disconnected' | 'error'
    Default: detected

    Set it yourself, or leave it out to detect it from the browser.

  • variant'panel' | 'badge' | 'banner'
    Default: 'panel'

    A card, an inline badge, or a bar shown only while something is wrong.

  • nameReactNode
    Default: 'Network connection'

    Connection name (panel).

  • detailsReactNode

    Optional connection detail.

  • latencynumber

    Latency in ms, shown while connected (measured by the probe when detecting).

  • probeUrlstring

    URL checked to prove the internet is reachable (detecting).

  • intervalnumber
    Default: 0

    Check again every this many ms (detecting).

  • timeoutnumber
    Default: 5000

    Give up on a check after this many ms (detecting).

  • showConnectionInfoboolean
    Default: false

    Show connection type, speed and data saver (detecting).

  • labelsPartial<Record<status, string>>

    Replace the text of any status.

  • onStatusChange(status, state?) => void

    Called when the status changes.

  • onRetry() => void

    Adds a retry action while disconnected or in error (detecting: also checks again).

  • alwaysShowboolean
    Default: false

    Keep the banner visible while connected.

  • classNamestring
    Default: ''

    Extra classes for the root element.

Related hooks and theme:useNetworkStatus