useNetworkState
This hook can track the user connection changes and return whether is online or offline with some of the user network informations.
Return Values
Name | Type | Description |
---|---|---|
isOnline | Boolean | determines whether the user is online or not. |
...informations | Object | the NetworkInformation about the user connection |
WARNING
Some of the NetworkInformation
properties may not supported in other browsers. checkout Browser compatibility
Example Usage
tsx
import { useNetworkState } from 'react-pre-hooks';
export default function Example() {
const { isOnline } = useNetworkState();
return (
<main>
<p>
You are <span>{isOnline ? 'online' : 'offline'}</span>.
</p>
</main>
);
}
import { useNetworkState } from 'react-pre-hooks';
export default function Example() {
const { isOnline } = useNetworkState();
return (
<main>
<p>
You are <span>{isOnline ? 'online' : 'offline'}</span>.
</p>
</main>
);
}