Monitor network connectivity status in real-time
Tags: connectivity wifi cellular online offline
The useNetwork composable provides real-time network connectivity monitoring. It tracks whether the device is connected, the connection type (wifi, cellular, none), and automatically updates when network status changes.
Import
<script>
import { useNetwork } from '@classic-homes/native/svelte';
</script>// React
import { useNetwork } from '@classic-homes/native/react';Basic Usage
<script lang="ts">
import { useNetwork } from '@classic-homes/native/svelte';
const network = useNetwork();
</script>
<div class={network.isConnected ? 'text-green-600' : 'text-red-600'}>
{network.isConnected ? 'Online' : 'Offline'}
</div>
{#if network.connectionType}
<p>Connection type: {network.connectionType}</p>
{/if}API Reference
| Property | Type | Description |
|---|---|---|
status |
NetworkStatus | null |
Full network status object |
isConnected |
boolean | null |
Whether device is connected to network |
connectionType |
ConnectionType | null |
Connection type ('wifi', 'cellular', 'none', etc.) |
isLoading |
boolean |
Whether status is being fetched |
error |
Error | null |
Current error if any |
refresh |
() => Promise<NetworkStatus> |
Manually refresh network status |
Accessibility
- Works with screen readers and assistive technologies
- Provides loading and error states for accessible status updates
- Keyboard accessible controls
Related Features
- Device - Get device information, battery status, and language
- App Lifecycle - Handle app state changes, deep links, and back button