useOnline
Detect the current online status of the browser.
The useOnline hook is helpful when you want to detect the current network online status of the browser.
The property returns a boolean value, with true meaning online and false meaning offline.
useOnline
Status is : 🟢
Try changing the network status from browser devtools settings or disconnect from internetUsage
Import the hook from @abhushanaj/react-hooks and use in required component;
import { useOnline } from '@abhushanaj/react-hooks';
function App() { const isOnline = useOnline(true);
return ( <div> <p>Status is : {isOnline ? '🟢' : '🔴'}</p> <p>Try changing the network status from browser devtools settings or disconnect from internet</p> </div> );}
export default App;API Reference
Parameters
| Parameter | Type | Description | Default |
|---|---|---|---|
| defaultStatus | boolean (optional) | The default status to use on server snapshots while SSR. | true |
Return Value
| Parameter | Type | Description | Default |
|---|---|---|---|
| isOnline | boolean | The current online status of the network. | true |