@@ -19,6 +19,8 @@ Check out [this medium article](https://blog.callstack.io/your-react-native-offl
19
19
+ [ ` Network reducer ` ] ( #network-reducer )
20
20
+ [ ` createNetworkMiddleware() ` ] ( #createnetworkmiddleware )
21
21
+ [ ` Offline Queue ` ] ( #offline-queue )
22
+ * [ Other Utilities] ( #other-utilities )
23
+ + [ ` checkInternetConnection ` ] ( #checkinternetconnection )
22
24
* [ Miscellanea] ( #miscellanea )
23
25
* [ FAQ] ( #faq )
24
26
* [ Contributions] ( #contributions )
@@ -408,6 +410,31 @@ fetchData.meta = {
408
410
}
409
411
```
410
412
413
+ ### Other utilities
414
+
415
+ #### ` checkInternetConnection() `
416
+ Utility function that allows you to query for internet connectivity on demand. If you have integrated this library with redux, you can then dispatch a ` CONNECTION_CHANGE ` action type to inform the ` network ` reducer accordingly and keep it up to date. Check the example below.
417
+
418
+ ``` js
419
+ checkInternetConnection (timeout?: number = 3000 , url?: string = ' http://www.google.com/' ): Promise < boolean>
420
+ ```
421
+
422
+ ##### Example
423
+
424
+ ``` js
425
+ import { checkInternetConnection , offlineActionTypes } from ' react-native-offline' ;
426
+
427
+ async function internetChecker (dispatch ) {
428
+ const isConnected = await checkInternetConnection ();
429
+ // Dispatching can be done inside a connected component, a thunk (where dispatch is injected), saga, or any sort of middleware
430
+ // In this example we are using a thunk
431
+ dispatch ({
432
+ type: offlineActionTypes .CONNECTION_CHANGE ,
433
+ payload: isConnected,
434
+ });
435
+ }
436
+ ```
437
+
411
438
## Miscellanea
412
439
413
440
### FAQ
@@ -427,7 +454,7 @@ As you can see in the snippets below, we create the `store` instance as usual an
427
454
import { AsyncStorage , Platform , NetInfo } from ' react-native' ;
428
455
import { createStore , applyMiddleware , compose } from ' redux' ;
429
456
import { persistStore , autoRehydrate } from ' redux-persist' ;
430
- import { createNetworkMiddleware , offlineActionTypes , checkInternetConnectionOnStartup } from ' react-native-offline' ;
457
+ import { createNetworkMiddleware , offlineActionTypes , checkInternetConnection } from ' react-native-offline' ;
431
458
import rootReducer from ' ../reducers' ;
432
459
433
460
const networkMiddleware = createNetworkMiddleware ();
@@ -450,7 +477,7 @@ export default function configureStore(callback) {
450
477
},
451
478
() => {
452
479
// After rehydration completes, we detect initial connection
453
- checkInternetConnectionOnStartup ().then (isConnected => {
480
+ checkInternetConnection ().then (isConnected => {
454
481
store .dispatch ({
455
482
type: offlineActionTypes .CONNECTION_CHANGE ,
456
483
payload: isConnected,
0 commit comments