Socket
Socket
Sign inDemoInstall

@react-native-community/netinfo

Package Overview
Dependencies
Maintainers
1
Versions
153
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-native-community/netinfo

React Native Network Info API for iOS & Android


Version published
Weekly downloads
676K
increased by2.98%
Maintainers
1
Weekly downloads
 
Created

What is @react-native-community/netinfo?

@react-native-community/netinfo is a React Native library that provides information about the device's network connection state. It allows developers to detect the type of network connection (WiFi, cellular, etc.), whether the device is connected to the internet, and other related details.

What are @react-native-community/netinfo's main functionalities?

Check current network state

This feature allows you to fetch the current network state, including the connection type (e.g., WiFi, cellular) and whether the device is connected to the internet.

import NetInfo from '@react-native-community/netinfo';

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

Subscribe to network state changes

This feature allows you to subscribe to network state changes, so you can react to changes in the network connection in real-time.

import NetInfo from '@react-native-community/netinfo';

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

// Later, you can unsubscribe to stop listening for updates
unsubscribe();

Check if the device is connected to the internet

This feature allows you to check if the device is currently connected to the internet.

import NetInfo from '@react-native-community/netinfo';

NetInfo.fetch().then(state => {
  console.log('Is connected?', state.isConnected);
});

Get detailed network information

This feature provides detailed information about the network connection, including whether the internet is reachable and additional details specific to the connection type.

import NetInfo from '@react-native-community/netinfo';

NetInfo.fetch().then(state => {
  console.log('Connection type', state.type);
  console.log('Is connected?', state.isConnected);
  console.log('Is internet reachable?', state.isInternetReachable);
  console.log('Details:', state.details);
});

Other packages similar to @react-native-community/netinfo

Keywords

FAQs

Package last updated on 20 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc