Notifies your app when the network goes offline and back online.
npm install react-native-netinfoNotifies your app when the network connection goes online or offline.
Inspired by react-network and react-native-offline, designed with a similar API to the former for when you need a simpler and lighter package than the latter.
```
npm install react-native-netinfoor with yarn
yarn add react-native-netinfo
`js
import { NetInfoProvider } from 'react-native-netinfo';
const App = () => (
console.log(isConnected);
console.log(connectionInfo);
}}
render={({ isConnected, connectionInfo }) =>
isConnected ? (
Effective connection type:{connectionInfo.effectiveType}
) : (
)
}
/>
);
`
`js
import { NetInfoProvider } from 'react-native-netinfo';
const App = () => (
console.log(isConnected);
console.log(connectionInfo);
}}
>
{({ isConnected, connectionInfo }) =>
isConnected ? (
Effective connection type:{connectionInfo.effectiveType}
) : (
)
}
);
`
`js
import { NetInfoProvider } from 'react-native-netinfo';
const ConnectedComponent = ({ isConnected, connectionInfo }) =>
isConnected ? (
) : (
);
const App = () => (
console.log(isConnected);
console.log(connectionInfo);
}}
component={ConnectedComponent}
/>
);
`
NB: you should not set both component and render props. If you were to do this, the render prop would be ignored.
This package also exposes constants for connection info's types and effective types.
You can use them like so:
`js
import { CONSTANTS } from 'react-native-netinfo';
const App = () => (
);
``
You can find the full list of types and effective types in the official React Native documentation about NetInfo.