|
1 | 1 | import { useState, useEffect } from 'react'; |
2 | 2 | import getEffectiveNetworkType from '#app/lib/utilities/getEffectiveNetworkType'; |
3 | | -import { EffectiveNetworkType, NetworkStatus } from './type'; |
| 3 | +import { NetworkStatus } from './type'; |
4 | 4 |
|
5 | 5 | /** |
6 | 6 | * A hook to monitor and provide real-time network connectivity status. |
7 | 7 | * Tracks whether the user is online or offline and includes the effective network type. |
8 | 8 | * @returns {NetworkStatus} An object containing isOnline (boolean), source ('browser'), and networkType (EffectiveNetworkType). |
9 | 9 | */ |
10 | 10 |
|
11 | | -interface NavigatorWithConnection extends Navigator { |
12 | | - connection?: { |
13 | | - effectiveType?: EffectiveNetworkType; |
14 | | - addEventListener?: (type: string, listener: () => void) => void; |
15 | | - removeEventListener?: (type: string, listener: () => void) => void; |
16 | | - }; |
17 | | -} |
18 | | - |
19 | 11 | const useNetworkStatusTracker = (): NetworkStatus => { |
20 | 12 | const [networkStatus, setNetworkStatus] = useState<NetworkStatus>(() => { |
21 | 13 | const isOnline = |
@@ -58,7 +50,7 @@ const useNetworkStatusTracker = (): NetworkStatus => { |
58 | 50 | window.addEventListener('online', handleOnline); |
59 | 51 | window.addEventListener('offline', handleOffline); |
60 | 52 |
|
61 | | - const { connection } = navigator as NavigatorWithConnection; |
| 53 | + const { connection } = navigator; |
62 | 54 |
|
63 | 55 | if (connection?.addEventListener) { |
64 | 56 | connection.addEventListener('change', handleConnectionChange); |
|
0 commit comments