useOnlineStatus
This hook helps you monitor the online status of a user within your application. It provides a simple way to determine whether the user's device is currently connected to the internet.
Usage
-
Make sure you have
@ridgehkr/useful
installed in your application. If not, you can get started by following the installation instructions. -
Import
useOnlineStatus
into your component.
import { useOnlineStatus } from '@ridgehkr/useful'
Example
This basic example displays a message indicating online status. (Note: to simulate offline status, you can use the Network tab in your browser's DevTools to disable the network connection.)
OnlineStatus.jsx
import { useOnlineStatus } from '@ridgehkr/useful'
function OnlineStatus() {
const isOnline = useOnlineStatus()
return (
<div>
{isOnline ? (
<p>You are currently online.</p>
) : (
<p>You are currently offline.</p>
)}
</div>
)
}
API Reference
Parameters
useOnlineStatus
does not accept any parameters.
Return Value
The hook returns a boolean indicating online status:
Property | Type | Description |
---|---|---|
isOnline | boolean | true if online, false if offline |