Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

react-native-netinfo

> 前端框架
Open source

React Native Network Info API for Android & iOS

2.2K stars0 likes3 views
WebsiteGitHub

About

React Native Network Info API for Android & iOS

@react-native-community/netinfo

React Native Network Info API for Android, iOS, macOS, Windows & Web. It allows you to get information on:

  • Connection type
  • Connection quality

Getting started

Install the library using either Yarn:

bash
yarn add @react-native-community/netinfo

or npm:

bash
npm install --save @react-native-community/netinfo

Using React Native >= 0.60

Linking the package manually is not required anymore with Autolinking.

  • iOS Platform:

    $ npx pod-install # CocoaPods on iOS needs this extra step

  • Android Platform with AndroidX:

    Modify your android/build.gradle configuration:

    buildscript {
      ext {
        buildToolsVersion = "xx.yy.zz"
        minSdkVersion = xyz
        compileSdkVersion = xyz
        targetSdkVersion = xyz
      }
  • macOS Platform:

    Autolinking is not yet available on macOS. See the Manual linking steps for macOS below.

Manually link the library on macOS
  1. Open your project .xcodeproj on xcode.

  2. Right click on the Libraries folder and select Add files to "yourProjectName".

  3. Add RNCNetInfo.xcodeproj (located at node_modules/@react-native-community/react-native-netinfo/macos) to your project Libraries.

  4. Go to Build Phases -> Link Binary with Libraries and add: libRNCNetInfo-macOS.a.

  • Windows Platform:

    Autolinking automatically works on RNW >= 0.63.

Minimum supported versions for windows

  • react-native-windows 0.63 or newer
  • MSVC build tools v142 (included in Visual Studio 2019) or newer
  • x86, x64, or arm64 are supported, arm (32-bit) is not supported

React Native Compatibility

To use this library you need to ensure you are using the correct version of React Native. We support react-native 0.60+ with auto-linking.

If you are using a version of React Native that is lower than 0.60 check older versions of this README for details, but no support will be provided.

Browser Compatilibity

The web implementation heavily depends on the Network Information API which is still an is an experimental technology and thus it's not supported in every browser. If this API is not available the library will safely fallback to the old onLine property and return basic connection information.

AbortController is used to cancel network requests, and may not be available on Internet Explorer, though it is available on Edge https://caniuse.com/abortcontroller

Node Compatibility

Node v16 is the minimum required node version - AbortController is only present in stable versions of node from v16 on

Migrating from the core react-native module

This module was created when the NetInfo was split out from the core of React Native. To migrate to this module you need to follow the installation instructions above and then change your imports from:

javascript
import { NetInfo } from "react-native";

to:

javascript
import NetInfo from "@react-native-community/netinfo";

Note that the API was updated after it was extracted from NetInfo to support some new features, however, the previous API is still available and works with no updates to your code.

Usage

Global vs isolated instance

Internally this library has a network state manager class to handle all the functionality and state. This library provides two options for instantiating the class:

  1. you can use global library functions which taps into a global singleton instance of the class
  2. or you can create isolated instances of the class to tap into, each being separately configured

Global instance functions:

Subscribe to network state updates:

javascript
import { addEventListener } from "@react-native-community/netinfo";

// Subscribe
const unsubscribe = addEventListener(state => {
  console.log("Connection type", state.type);
  console.log("Is connected?", state.isConnected);
});

// Unsubscribe
unsubscribe();

Get the network state once:

javascript
import { fetch } from "@react-native-community/netinfo";

fetch().then(state => {
  console.log("Connection type", state.type);
  console.log("Is connected?", state.isConnected);
});

Get network state updates from the global instance via a react hook:

javascript
import { useNetInfo } from "@react-native-community/netinfo";

const { type, isConnected } = useNetInfo();

Isolated instance:

Use an isolated instance of the network manager:

javascript
import { useNetInfoInstance } from "@react-native-community/netinfo";

const { netInfo: { type, isConnected }, refresh } = useNetInfoInstance();

API

  • Types:
    • NetInfoState
    • NetInfoStateType
    • NetInfoCellularGeneration
  • Global instance methods:
    • fetch()
    • refresh()
    • addEventListener()
    • useNetInfo()
  • Isolated instance:
    • useNetInfoInstance()

Types

NetInfoState

Describes the current state of the network. It is an object with these properties:

Property Type Description
type NetInfoStateType The type of the current connection.
isConnected boolean, null If there is an active network connection. Defaults to null on most platforms for unknown networks. Note: Web browsers report network type unknown for many otherwise valid networks (https://caniuse.com/netinfo), so isConnected may be true or false and represent a real connection status even for unknown network types in certain cases.
isInternetReachable boolean, null If the internet is reachable with the currently active network connection. If unknown defaults to null
isWifiEnabled boolean (Android only) Whether the device's WiFi is ON or OFF.
details The value depends on the type value. See below.

The details value depends on the type value.

type is none or unknown

details is null.

type is wifi

details has these properties:

Property Platform Type Description
isConnectionExpensive Android, iOS, macOS, Windows, Web boolean If the network connection is considered "expensive". This could be in either energy or monetary terms.
ssid Android, iOS (not tvOS), Windows string The SSID of the network. May not be present, null, or an empty string if it cannot be determined. On iOS, your app must meet at least one of the following requirements and you must set the shouldFetchWiFiSSID configuration option or no attempt will be made to fetch the SSID. On Android, you need to have the ACCESS_FINE_LOCATION permission in your AndroidManifest.xml and accepted by the user.
bssid Android, iOS (not tvOS), Windows* string The BSSID of the network. May not be present, null, or an empty string if it cannot be determined. On iOS, make sure your app meets at least one of the following requirements. On Android, you need to have the ACCESS_FINE_LOCATION permission in your AndroidManifest.xml and accepted by the user.
strength Android, Windows number An integer number from 0 to 100 for the signal strength. May not be present if the signal strength cannot be determined.
ipAddress Android, iOS, macOS, Windows string The external IP address. Can be in IPv4 or IPv6 format. May not be present if it cannot be determined.
subnet Android, iOS, macOS string The subnet mask in IPv4 format. May not be present if it cannot be determined.
frequency Android, Windows* number Network frequency. Example: For 2.4 GHz networks, the method will return 2457. May not be present if it cannot be determined.
linkSpeed Android number The link speed in Mbps.
rxLinkSpeed Android number The current receive link speed in Mbps. (Android Q / API level 29 and above)
txLinkSpeed Android number The current transmit link speed in Mbps. (Android Q / API level 29 and above)

* Requires wiFiControl capability in appxmanifest. Without it, these values will be null.

type is cellular

details has these properties:

Property Platform Type Description
isConnectionExpensive Android, iOS, macOS, Windows, Web boolean If the network connection is considered "expensive". This could be in either energy or monetary terms.
cellularGeneration Android, iOS, Windows NetInfoCellularGeneration The generation of the cell network the user is connected to. This can give an indication of speed, but no guarantees.
carrier Android, iOS string The network carrier name. May not be present or may be empty if none can be determined.
type is bluetooth, ethernet, wimax, vpn, or other

details has these properties:

Property Type Description

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptnetworknetworkingreact-native

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架