Skip to content

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 internet

Usage

Import the hook from @abhushanaj/react-hooks and use in required component;

./src/App.tsx
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

ParameterTypeDescriptionDefault
defaultStatusboolean (optional)The default status to use on server snapshots while SSR.true

Return Value

ParameterTypeDescriptionDefault
isOnlinebooleanThe current online status of the network.true