1.0.0 • Published 6 months ago
react-connection-status v1.0.0
use-online-status
A simple, custom React hook to track the online/offline status of the user in both browser and React applications.
Installation
Install using npm:
npm install use-online-status
Usage
For example, in a web environment:
import React from 'react';
import useOnlineStatus from 'use-online-status'; // Import the custom hook
const ExampleComponent = () => {
const isOnline = useOnlineStatus(); // Use the hook to get the current online status
return (
<div>
<h1>{isOnline ? 'You are online' : 'You are offline'}</h1>
{!isOnline && <p>Please check your internet connection.</p>}
</div>
);
};
export default ExampleComponent;
1.0.0
6 months ago