Skip to content
usefy

NetworkIndicator

ComponentsConnectivity status

Drop-in React online/offline status banner

Live demo

Install

$ npm install @usefy/network-indicator

Quick start

NetworkIndicator.tsx
import { NetworkIndicator } from "@usefy/network-indicator";

function App() {
  return (
    <>
      <YourApp />
      {/* Mount once at the root — renders nothing while online */}
      <NetworkIndicator />
    </>
  );
}

API reference

<NetworkIndicator /> Props

PropTypeDefaultDescription
position"top" | "bottom""top"Which screen edge the fixed banner is pinned to.
offlineMessageReactNode"You're offline. Some features may not work."Content of the offline banner.
onlineMessageReactNode"Back online"Content of the reconnected confirmation.
onlineDurationnumber3000How long (ms) the confirmation stays before auto-dismissing. 0 or negative disables it. Changing it mid-confirmation restarts the timer from zero with the new duration.
render(state: NetworkIndicatorState) => ReactNodeEscape hatch: replaces the default banner entirely; called on every render (including steady-state online) with { online, reconnected }.
onStatusChange(online: boolean) => voidCalled after each online/offline transition (never on mount).
classNamestringClass applied to the default banner element.
styleCSSPropertiesInline styles merged over the defaults (yours win).

NetworkIndicatorState

interface NetworkIndicatorState {
  /** Current connectivity, from navigator.onLine (true on the server). */
  online: boolean;
  /** True during the "back online" confirmation window. */
  reconnected: boolean;
}

Other exports

ExportDescription
NetworkIndicatorPropsProps type.
NetworkIndicatorPosition"top" | "bottom".
DEFAULT_OFFLINE_MESSAGE / DEFAULT_ONLINE_MESSAGE / DEFAULT_ONLINE_DURATIONThe defaults, for reuse in custom render UIs.

The default banner also exposes data-status="offline" | "reconnected" and data-position attributes for styling and testing.


Go deeper

This page is the quick reference. For every example, prop, and edge case, read the full README — or open Storybook to change props live.

More in components