@react-native-community/netinfo
- Version 11.4.1
- Published
- 547 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
Functions
Interfaces
Enums
Type Aliases
Variables
variable _default
const _default: { configure: typeof configure; fetch: typeof fetch; refresh: typeof refresh; addEventListener: typeof addEventListener; useNetInfo: typeof useNetInfo; useNetInfoInstance: typeof useNetInfoInstance;};
Functions
function addEventListener
addEventListener: ( listener: Types.NetInfoChangeHandler) => Types.NetInfoSubscription;
Subscribe to the global singleton's 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. The configuration sets up a global singleton instance.
Parameter configuration
The new configuration to set.
function fetch
fetch: (requestedInterface?: string) => Promise<Types.NetInfoState>;
Returns a
Promise
that resolves to aNetInfoState
object. This function operates on the global singleton instance configured usingconfigure()
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 global singleton managed by this library.
Returns
A Promise which contains the updated connection state.
function useNetInfo
useNetInfo: ( configuration?: Partial<Types.NetInfoConfiguration>) => Types.NetInfoState;
A React Hook into this library's singleton which updates when the connection state changes.
Parameter configuration
Configure the isolated network checker managed by this hook
Returns
The connection state.
function useNetInfoInstance
useNetInfoInstance: ( isPaused?: boolean, configuration?: Partial<Types.NetInfoConfiguration>) => { netInfo: Types.NetInfoState; refresh: () => void };
A React Hook which manages an isolated instance of the network info manager. This is not a hook into a singleton shared state. NetInfo.configure, NetInfo.addEventListener, NetInfo.fetch, NetInfo.refresh are performed on a global singleton and have no affect on this hook.
Parameter isPaused
Pause the internal network checks.
Parameter configuration
Configure the isolated network checker managed by this hook
Returns
the netInfo state and a refresh function
Interfaces
interface NetInfoConfiguration
interface NetInfoConfiguration {}
property reachabilityHeaders
reachabilityHeaders?: Record<string, string>;
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 isWifiEnabled
isWifiEnabled?: boolean;
property type
type: NetInfoStateType.unknown;
Enums
enum NetInfoCellularGeneration
enum NetInfoCellularGeneration { '2g' = '2g', '3g' = '3g', '4g' = '4g', '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.
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)
- @babel/core
- @babel/preset-env
- @babel/runtime
- @react-native-community/bob
- @react-native/eslint-config
- @react-native/metro-config
- @semantic-release/changelog
- @semantic-release/git
- @tsconfig/react-native
- @types/jest
- @types/react
- @types/react-test-renderer
- @typescript-eslint/eslint-plugin
- @typescript-eslint/parser
- babel-jest
- babel-loader
- eslint
- eslint-config-prettier
- eslint-plugin-prettier
- html-webpack-plugin
- husky
- jest
- jest-expo
- jest-fetch-mock
- lint-staged
- metro-react-native-babel-preset
- prettier
- react
- react-dom
- react-native
- react-native-macos
- react-native-test-app
- react-native-web
- react-native-windows
- react-test-renderer
- rimraf
- semantic-release
- source-map-loader
- ts-jest
- ts-loader
- typescript
- webpack
- webpack-cli
- webpack-dev-server
Peer Dependencies (1)
Badge
To add a badge like this oneto 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>
- Updated .
Package analyzed in 4383 ms. - Missing or incorrect documentation? Open an issue for this package.