API Reference
useOnlineStatus

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

  1. Make sure you have @ridgehkr/useful installed in your application. If not, you can get started by following the installation instructions.

  2. 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:

PropertyTypeDescription
isOnlinebooleantrue if online, false if offline