useConnectionStatus
import { useConnectionStatus } from '@bbc/front-end-kit/vue'
Composable that provides reactive properties to know if the user is connected to the internet or not.
Tips
This composable is a wrapper around the Connections Status utility.
Warning
At this moment the composable is limited to 1 url for the whole codebase.
Should not be an issue in most cases.
Getting started
import { useConnectionStatus } from '@bbc/front-end-kit/vue'
const connectionStatus = useConnectionStatus();
API
Init
useConnectionStatus(url, options)
Parameters
url(optional): The URL to ping for the connection test. Defaults tonull— the underlying utility determines the fallback URL.options(optional): Configuration optionsinterval(optional): Time in ms between connection checks. Defaults to5000.timeout(optional): Maximum time in ms to wait for a ping response. Defaults to3000.supressWarnings(optional): Suppress console warnings when the URL has already been set by a previous call. Defaults tofalse. Note:supressis a known typo in the source — use singlepto match.
Single instance
The URL and interval are set on the first call and ignored on all subsequent calls. If a different URL is passed later, a warning is logged (unless supressWarnings is true).
Reactive properties
status
Computed string indicating the current connection state.
Values: 'online' | 'offline'
isOnline
Reactive boolean — true when the ping to the target URL succeeds. Indicates internet connectivity (not just network connectivity).
Values: Ref<Boolean>
isOffline
Reactive boolean — the inverse of isOnline.
Values: Ref<Boolean>
isChecking
Reactive boolean — true while a ping is in progress.
Values: Ref<Boolean>
isConnected
Reactive boolean — mirrors navigator.onLine. Indicates whether the device is connected to a network, not necessarily the internet.
Values: Ref<Boolean>
pingCache
The shared ping cache object from the underlying utility. Useful for inspecting cached results during debugging.
Values: Map
Methods
check
Manually trigger a connectivity check. Updates all reactive properties.