Rehooks

useStatus

Returns the current online/offline status of the client.

useStatus

Installation

npx rehooks-cli@latest add useStatus

Usage

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

API

useStatus

useStatus.ts
function useStatus(callback?: (isOnline: boolean) => void): boolean;

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