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 authored and rtivital committed Feb 16, 2024
1 parent d7b238b commit 61eb5f0
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/@mantine/hooks/src/use-network/use-network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ export function useNetwork() {
return () => _navigator.connection.removeEventListener('change', handleConnectionChange);
}

if (typeof _navigator.onLine === 'boolean') {
// Required for Firefox and other browsers that don't support navigator.connection
setStatus((current) => ({ ...current, online: _navigator.onLine }));
}

return undefined;
}, []);

Expand Down

0 comments on commit 61eb5f0

Please sign in to comment.