react-native-use-internet-status
v0.1.0
Published
A lightweight React Native hook to check if the device is connected to the internet.
Maintainers
Readme
react-native-use-internet-status
A simple React Native hook to check if the device is connected to the internet.
Features
- 🔌 Simple hook to check internet connectivity in React Native.
- ⚡ Lightweight and built on top of
@react-native-community/netinfo. - 🛠️ Easy to integrate in any project – just import and use.
Installation
You can install the package using either npm or yarn:
With npm
npm install react-native-use-internet-statusWith yarn
yarn add react-native-use-internet-statusPeer dependency
This package requires @react-native-community/netinfo.
If it’s not already installed in your project, install it as well:
With npm
npm install @react-native-community/netinfoWith yarn
yarn add @react-native-community/netinfoUsage
Import the hook and use it in your component to track internet connectivity:
import { Text, View } from 'react-native';
import useInternetStatus from 'react-native-use-internet-status';
const App = () => {
const { isConnected } = useInternetStatus();
if (isConnected === null) {
return <Text>Checking connection...</Text>;
}
return (
<View>
{isConnected ? (
<Text>You are Online ✅</Text>
) : (
<Text>No Internet Connection ❌</Text>
)}
</View>
);
};
export default App;License
This project is licensed under the MIT License – see the LICENSE for more details.
