---
name: "onNetworkStatusChange"
mode: "kit"
versionRequirements:
  - { name: "BaseKit", version: "2.0.1" }
  - { name: "@ray-js/ray", version: "0.3.23" }
platform:
  - "iOS"
  - "Android"
async: true
---

## onNetworkStatusChange

> [VERSION] BaseKit >= 2.0.1 | @ray-js/ray >= 0.3.23

> [PLATFORM] iOS, Android

> ⚡ **Supports Promise** — Returns a Promise when success / fail / complete callbacks are omitted.

### Description

Listen for network status changes. Note: On Android, this event only notifies that the network state changed. To get the latest network status, call the getNetworkType API again. Note: On Android, when the network state changes, the system may not update the network status immediately; there can be a delay. Therefore, when this event is triggered, you may need to call getNetworkType with a delay to obtain the latest information.

### Parameters

`(listener: Function)`

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `listener` | `(params: Object) => void` | Yes | - |  |

##### onNetworkStatusChange.listener(params) properties

| Property | Type | Required | Default | Since | Description |
| --- | --- | --- | --- | --- | --- |
| `isConnected` | `boolean` | Yes | - | `2.0.1` | Whether there is currently a network connection |
| `networkType` | `string` | Yes | - | `2.0.1` | Network type |


### Examples

#### Demo

```tsx
import { onNetworkStatusChange } from '@ray-js/ray'

// Listen for network status changes; when switching networks (toggle Wi-Fi / Airplane mode), the callback returns the connection state and network type
onNetworkStatusChange(e => {
  console.log("Network changed:", e.isConnected, e.networkType);
});
// Changes are triggered by switching networks; keep the listener active for a while
await new Promise(resolve => setTimeout(resolve, 8000));
```
