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.
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.
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.
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:detectedSet 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.
nameReactNodeDefault:'Network connection'Connection name (panel).
detailsReactNodeOptional connection detail.
latencynumberLatency in ms, shown while connected (measured by the probe when detecting).
probeUrlstringURL checked to prove the internet is reachable (detecting).
intervalnumberDefault:0Check again every this many ms (detecting).
timeoutnumberDefault:5000Give up on a check after this many ms (detecting).
showConnectionInfobooleanDefault:falseShow connection type, speed and data saver (detecting).
labelsPartial<Record<status, string>>Replace the text of any status.
onStatusChange(status, state?) => voidCalled when the status changes.
onRetry() => voidAdds a retry action while disconnected or in error (detecting: also checks again).
alwaysShowbooleanDefault:falseKeep the banner visible while connected.
classNamestringDefault:''Extra classes for the root element.
| Prop | Type | Default | Description |
|---|---|---|---|
status | 'connected' | 'connecting' | 'disconnected' | 'error' | detected | Set it yourself, or leave it out to detect it from the browser. |
variant | 'panel' | 'badge' | 'banner' | 'panel' | A card, an inline badge, or a bar shown only while something is wrong. |
name | ReactNode | 'Network connection' | Connection name (panel). |
details | ReactNode | – | Optional connection detail. |
latency | number | – | Latency in ms, shown while connected (measured by the probe when detecting). |
probeUrl | string | – | URL checked to prove the internet is reachable (detecting). |
interval | number | 0 | Check again every this many ms (detecting). |
timeout | number | 5000 | Give up on a check after this many ms (detecting). |
showConnectionInfo | boolean | false | Show connection type, speed and data saver (detecting). |
labels | Partial<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). |
alwaysShow | boolean | false | Keep the banner visible while connected. |
className | string | '' | Extra classes for the root element. |
Related hooks and theme:useNetworkStatus