title: Taro.onNetworkStatusChange(callback)

sidebar_label: onNetworkStatusChange

Listens on the network status change event.

Reference

Type

  1. (callback: Callback) => void

Parameters

Callback

The callback function for the network status change event.

  1. (result: CallbackResult) => void
Property Type
result CallbackResult

CallbackResult

Property Type Description
isConnected boolean Indicates whether it is connected to the network
networkType "wifi" | "2g" | "3g" | "4g" | "unknown" | "none" Network type

Sample Code

  1. Taro.onNetworkStatusChange(function (res) {
  2. console.log(res.isConnected)
  3. console.log(res.networkType)
  4. })

API Support

API WeChat Mini-Program H5 React Native
Taro.onNetworkStatusChange ✔️ ✔️ ✔️