Rehooks
Content

useOnlineStatus

A hook that returns the current online/offline status of the client.

useOnlineStatus

Usage

Component.tsx
import { useOnlineStatus } from "~/hooks/useOnlineStatus";
 
function Component() {
  const isOnline = useOnlineStatus();
  return <p>Is online: {isOnline ? "Yes" : "No"}</p>;
}

API

useOnlineStatus

function useOnlineStatus(callback?: (isOnline: boolean) => void): boolean;

Returns the current online/offline status of the client.

Parameters

NameTypeDescription
callback?(isOnline: boolean) => voidOptional callback to run on status change. The callback function receives a boolean value indicating the current online/offline status of the client. If the callback is not provided, the function will not run on status change. This is useful for triggering actions based on the online status, such as displaying a loading indicator or disabling certain features.

Returns

NameTypeDescription
isOnlinebooleantrue if online, false if offline. This value is updated whenever the online status changes.

On this page