Skip to main content
Version: Next

Taro.onNetworkStatusChange(callback)

Listens on the network status change event.

Reference

Type

(callback: Callback) => void

Parameters

Callback

The callback function for the network status change event.

(result: CallbackResult) => void
PropertyType
resultCallbackResult

CallbackResult

PropertyTypeDescription
isConnectedbooleanIndicates whether it is connected to the network
networkType"wifi" | "2g" | "3g" | "4g" | "unknown" | "none"Network type

Sample Code

Taro.onNetworkStatusChange(function (res) {
console.log(res.isConnected)
console.log(res.networkType)
})

API Support

APIWeChat Mini-ProgramH5React Native
Taro.onNetworkStatusChange✔️✔️✔️