react-online-staus
v1.0.0
Published
A simple React Hook for detecting online/offline status.
Downloads
78
Maintainers
Readme
react-online-status
A lightweight React Hook for effortlessly detecting online/offline network status. Stay connected and informed!
Why react-online-status?
- Tiny Footprint: Minimal impact on your bundle size.
- Simple API: Easy to use and integrate into your React projects.
- Real-time Updates: Get instant notifications about network changes.
- TypeScript Support: Enjoy type safety and improved developer experience.
Installation
npm install react-online-status
# or
yarn add react-online-status
## Usage
```jsx
import { useOnlineStatus } from "react-online-status";
function MyComponent() {
const isOnline = useOnlineStatus();
return <div>You are currently {isOnline ? "Online" : "Offline"}.</div>;
}
```
## Example with Conditional Rendering
```jsx
import { useOnlineStatus } from "react-online-status";
function MyComponent() {
const isOnline = useOnlineStatus();
return (
<div>
{isOnline ? (
<p>Syncing data...</p>
) : (
<p>You are offline. Data will be synced when you reconnect.</p>
)}
</div>
);
}
```
## Handling Network Changes
You can use the `isOnline` boolean value to trigger actions based on network connectivity changes. For example, you can display a notification, disable certain features, or queue data synchronization for later.