diff --git a/README.md b/README.md index 49aab29a..d2280b06 100644 --- a/README.md +++ b/README.md @@ -246,8 +246,8 @@ Describes the current state of the network. It is an object with these propertie | Property | Type | Description | | --------------------- | --------------------------------------- | -------------------------------------------------------------------------------------------------- | | `type` | [`NetInfoStateType`](#netinfostatetype) | The type of the current connection. | -| `isConnected` | `boolean` | If there is an active network connection. Note that this DOES NOT mean that internet is reachable. | -| `isInternetReachable` | `boolean` | If the internet is reachable with the currently active network connection. | +| `isConnected` | `boolean`, `null` | If there is an active network connection. If unknown defaults to `null`. | +| `isInternetReachable` | `boolean`, `null` | If the internet is reachable with the currently active network connection. If unknown defaults to `null` | | `isWifiEnabled` | `boolean` | *(Android only)* Whether the device's WiFi is ON or OFF. | | `details` | | The value depends on the `type` value. See below. | diff --git a/src/index.ts b/src/index.ts index 5e4aa746..14618523 100644 --- a/src/index.ts +++ b/src/index.ts @@ -96,8 +96,8 @@ export function useNetInfo( const [netInfo, setNetInfo] = useState({ type: Types.NetInfoStateType.unknown, - isConnected: false, - isInternetReachable: false, + isConnected: null, + isInternetReachable: null, details: null, }); diff --git a/src/internal/internetReachability.ts b/src/internal/internetReachability.ts index 7088c888..e6c521c2 100644 --- a/src/internal/internetReachability.ts +++ b/src/internal/internetReachability.ts @@ -31,7 +31,7 @@ export default class InternetReachability { } private _setIsInternetReachable = ( - isInternetReachable: boolean | null | undefined, + isInternetReachable: boolean | null, ): void => { if (this._isInternetReachable === isInternetReachable) { return; @@ -41,7 +41,7 @@ export default class InternetReachability { this._listener(this._isInternetReachable); }; - private _setExpectsConnection = (expectsConnection: boolean): void => { + private _setExpectsConnection = (expectsConnection: boolean | null): void => { // Cancel any pending check if (this._currentInternetReachabilityCheckHandler !== null) { this._currentInternetReachabilityCheckHandler.cancel(); diff --git a/src/internal/nativeModule.web.ts b/src/internal/nativeModule.web.ts index 7c8889d1..e03ff108 100644 --- a/src/internal/nativeModule.web.ts +++ b/src/internal/nativeModule.web.ts @@ -213,8 +213,8 @@ const getCurrentState = ( } else if (type === NetInfoStateType.unknown) { const state: NetInfoUnknownState = { ...baseState, - isConnected: false, - isInternetReachable: false, + isConnected: null, + isInternetReachable: null, type, details: null, }; diff --git a/src/internal/types.ts b/src/internal/types.ts index f0d81a28..5608e4bc 100644 --- a/src/internal/types.ts +++ b/src/internal/types.ts @@ -35,7 +35,7 @@ interface NetInfoConnectedState< > { type: T; isConnected: true; - isInternetReachable: boolean | null | undefined; + isInternetReachable: boolean | null; details: D & NetInfoConnectedDetails; isWifiEnabled?: boolean; } @@ -47,9 +47,13 @@ interface NetInfoDisconnectedState { details: null; } -export type NetInfoUnknownState = NetInfoDisconnectedState< - NetInfoStateType.unknown ->; +export interface NetInfoUnknownState { + type: NetInfoStateType.unknown; + isConnected: null; + isInternetReachable: null; + details: null; +} + export type NetInfoNoConnectionState = NetInfoDisconnectedState< NetInfoStateType.none >;