@react-native-community/netinfo

  • Version 9.3.0
  • Published
  • 498 kB
  • No dependencies
  • MIT license

Install

npm i @react-native-community/netinfo
yarn add @react-native-community/netinfo
pnpm add @react-native-community/netinfo

Overview

React Native Network Info API for iOS & Android

Index

Variables

variable _default

const _default: {
configure: typeof configure;
fetch: typeof fetch;
refresh: typeof refresh;
addEventListener: typeof addEventListener;
useNetInfo: typeof useNetInfo;
};

    Functions

    function addEventListener

    addEventListener: (
    listener: Types.NetInfoChangeHandler
    ) => Types.NetInfoSubscription;
    • Subscribe to connection information. The callback is called with a parameter of type [NetInfoState](README.md#netinfostate) whenever the connection state changes. Your listener will be called with the latest information soon after you subscribe and then with any subsequent changes afterwards. You should not assume that the listener is called in the same way across devices or platforms.

      Parameter listener

      The listener which is called when the network state changes.

      Returns

      A function which can be called to unsubscribe.

    function configure

    configure: (configuration: Partial<Types.NetInfoConfiguration>) => void;
    • Configures the library with the given configuration. Note that calling this will stop all previously added listeners from being called again. It is best to call this right when your application is started to avoid issues.

      Parameter configuration

      The new configuration to set.

    function fetch

    fetch: (requestedInterface?: string) => Promise<Types.NetInfoState>;
    • Returns a Promise that resolves to a NetInfoState object.

      Parameter requestedInterface

      interface from which to obtain the information

      Returns

      A Promise which contains the current connection state.

    function refresh

    refresh: () => Promise<Types.NetInfoState>;
    • Force-refreshes the internal state of the NetInfo library.

      Returns

      A Promise which contains the updated connection state.

    function useNetInfo

    useNetInfo: (
    configuration?: Partial<Types.NetInfoConfiguration>
    ) => Types.NetInfoState;
    • A React Hook which updates when the connection state changes.

      Returns

      The connection state.

    Interfaces

    interface NetInfoConfiguration

    interface NetInfoConfiguration {}

      property reachabilityLongTimeout

      reachabilityLongTimeout: number;

        property reachabilityMethod

        reachabilityMethod?: NetInfoMethodType;

          property reachabilityRequestTimeout

          reachabilityRequestTimeout: number;

            property reachabilityShortTimeout

            reachabilityShortTimeout: number;

              property reachabilityShouldRun

              reachabilityShouldRun: () => boolean;

                property reachabilityTest

                reachabilityTest: (response: Response) => Promise<boolean>;

                  property reachabilityUrl

                  reachabilityUrl: string;

                    property shouldFetchWiFiSSID

                    shouldFetchWiFiSSID: boolean;

                      property useNativeReachability

                      useNativeReachability: boolean;

                        interface NetInfoConnectedDetails

                        interface NetInfoConnectedDetails {}

                          property isConnectionExpensive

                          isConnectionExpensive: boolean;

                            interface NetInfoUnknownState

                            interface NetInfoUnknownState {}

                              property details

                              details: null;

                                property isConnected

                                isConnected: boolean | null;

                                  property isInternetReachable

                                  isInternetReachable: null;

                                    property type

                                    type: NetInfoStateType.unknown;

                                      Enums

                                      enum NetInfoCellularGeneration

                                      enum NetInfoCellularGeneration {
                                      '2g' = '2g',
                                      '3g' = '3g',
                                      '4g' = '4g',
                                      '5g' = '5g',
                                      }

                                        member '2g'

                                        '2g' = '2g'

                                          member '3g'

                                          '3g' = '3g'

                                            member '4g'

                                            '4g' = '4g'

                                              member '5g'

                                              '5g' = '5g'

                                                enum NetInfoStateType

                                                enum NetInfoStateType {
                                                unknown = 'unknown',
                                                none = 'none',
                                                cellular = 'cellular',
                                                wifi = 'wifi',
                                                bluetooth = 'bluetooth',
                                                ethernet = 'ethernet',
                                                wimax = 'wimax',
                                                vpn = 'vpn',
                                                other = 'other',
                                                }
                                                • Copyright (c) Facebook, Inc. and its affiliates.

                                                  This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree.

                                                member bluetooth

                                                bluetooth = 'bluetooth'

                                                  member cellular

                                                  cellular = 'cellular'

                                                    member ethernet

                                                    ethernet = 'ethernet'

                                                      member none

                                                      none = 'none'

                                                        member other

                                                        other = 'other'

                                                          member unknown

                                                          unknown = 'unknown'

                                                            member vpn

                                                            vpn = 'vpn'

                                                              member wifi

                                                              wifi = 'wifi'

                                                                member wimax

                                                                wimax = 'wimax'

                                                                  Type Aliases

                                                                  type NetInfoBluetoothState

                                                                  type NetInfoBluetoothState = NetInfoConnectedState<NetInfoStateType.bluetooth>;

                                                                    type NetInfoCellularState

                                                                    type NetInfoCellularState = NetInfoConnectedState<
                                                                    NetInfoStateType.cellular,
                                                                    {
                                                                    cellularGeneration: NetInfoCellularGeneration | null;
                                                                    carrier: string | null;
                                                                    }
                                                                    >;

                                                                      type NetInfoChangeHandler

                                                                      type NetInfoChangeHandler = (state: NetInfoState) => void;

                                                                        type NetInfoConnectedStates

                                                                        type NetInfoConnectedStates =
                                                                        | NetInfoCellularState
                                                                        | NetInfoWifiState
                                                                        | NetInfoBluetoothState
                                                                        | NetInfoEthernetState
                                                                        | NetInfoWimaxState
                                                                        | NetInfoVpnState
                                                                        | NetInfoOtherState;

                                                                          type NetInfoDisconnectedStates

                                                                          type NetInfoDisconnectedStates = NetInfoUnknownState | NetInfoNoConnectionState;

                                                                            type NetInfoEthernetState

                                                                            type NetInfoEthernetState = NetInfoConnectedState<
                                                                            NetInfoStateType.ethernet,
                                                                            {
                                                                            ipAddress: string | null;
                                                                            subnet: string | null;
                                                                            }
                                                                            >;

                                                                              type NetInfoMethodType

                                                                              type NetInfoMethodType = 'HEAD' | 'GET';

                                                                                type NetInfoNoConnectionState

                                                                                type NetInfoNoConnectionState = NetInfoDisconnectedState<NetInfoStateType.none>;

                                                                                  type NetInfoOtherState

                                                                                  type NetInfoOtherState = NetInfoConnectedState<NetInfoStateType.other>;

                                                                                    type NetInfoState

                                                                                    type NetInfoState = NetInfoDisconnectedStates | NetInfoConnectedStates;

                                                                                      type NetInfoSubscription

                                                                                      type NetInfoSubscription = () => void;

                                                                                        type NetInfoVpnState

                                                                                        type NetInfoVpnState = NetInfoConnectedState<NetInfoStateType.vpn>;

                                                                                          type NetInfoWifiState

                                                                                          type NetInfoWifiState = NetInfoConnectedState<
                                                                                          NetInfoStateType.wifi,
                                                                                          {
                                                                                          ssid: string | null;
                                                                                          bssid: string | null;
                                                                                          strength: number | null;
                                                                                          ipAddress: string | null;
                                                                                          subnet: string | null;
                                                                                          frequency: number | null;
                                                                                          linkSpeed: number | null;
                                                                                          rxLinkSpeed: number | null;
                                                                                          txLinkSpeed: number | null;
                                                                                          }
                                                                                          >;

                                                                                            type NetInfoWimaxState

                                                                                            type NetInfoWimaxState = NetInfoConnectedState<NetInfoStateType.wimax>;

                                                                                              Package Files (2)

                                                                                              Dependencies (0)

                                                                                              No dependencies.

                                                                                              Dev Dependencies (44)

                                                                                              Peer Dependencies (1)

                                                                                              Badge

                                                                                              To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                              You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@react-native-community/netinfo.

                                                                                              • Markdown
                                                                                                [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@react-native-community/netinfo)
                                                                                              • HTML
                                                                                                <a href="https://www.jsdocs.io/package/@react-native-community/netinfo"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>