Skip to content

Commit

Permalink
[@mantine/hooks] Fixed initial value of the online attribute return…
Browse files Browse the repository at this point in the history
…ed by `useNetwork()` in Firefox (#5766)

* [@mantine/hooks] Fixed initial value of the `online` attribute returned by `useNetwork()`

* Update use-network.ts

[@mantine/hooks] Set the online status for environments without `navigator.connection` in `useNetwork()`
  • Loading branch information
jalik committed Feb 16, 2024
1 parent d7b238b commit 61bf3c0
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/@mantine/hooks/src/use-network/use-network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export function useNetwork() {
setStatus({ online: _navigator.onLine, ...getConnection() });
_navigator.connection.addEventListener('change', handleConnectionChange);
return () => _navigator.connection.removeEventListener('change', handleConnectionChange);
} else if (typeof _navigator.onLine === 'boolean') {
// Set online status without navigator.connection information.
// https://caniuse.com/netinfo
setStatus({ online: _navigator.onLine });
}

return undefined;
Expand Down

0 comments on commit 61bf3c0

Please sign in to comment.