🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

react-native-connection-info

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-connection-info

Higher order component for React Native to detect network connection state.

1.1.0
latest
Version published
Weekly downloads
3
-25%
Maintainers
1
Weekly downloads
 
Created

react-native-connection-info

travis build version downloads MIT license github

Higher order component for React Native to detect network connection state.

Use withConnection to inject the connection object which currently has the isConnected property. This is a boolean value that indicates internet connectivity status (see the NetInfo documentation on isConnected).

Usage

Installation

npm install --save react-native-connection-info

Android

Make sure to also include permissions on Android. Add the following line to your AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Examples

import React from 'react';
import {
  Text,
  View,
} from 'react-native';
import { withConnection, connectionShape } from 'react-native-connection-info';

const MyComponent = ({ connection }) => (
  <View>
    <Text
      style={{ color: connection.isConnected ? 'lightskyblue' : 'lightcoral' }}
    >
      {connection.isConnected ? 'Connected' : 'Offline'}
    </Text>
  </View>
)

MyComponent.propTypes = {
  connection: connectionShape,
};

export default withConnection(MyComponent);

Redux Wrapped Instance

Usage with redux is supported by default.

This section is only used if you need to reference the wrapped instance using getWrappedInstance() when using react-redux's connect(). This component uses { withRef: true }.

Usage

// instead of importing from 'react-native-connection-info'
// import { withConnection, connectionShape } from 'react-native-connection-info';
// just add /redux
import { withConnection, connectionShape } from 'react-native-connection-info/redux';

The rest is the same as in the first example.

FAQs

Package last updated on 23 Aug 2016

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