You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+83-9Lines changed: 83 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -102,17 +102,20 @@ import NetInfo from "@react-native-community/netinfo";
102
102
Note that the API was updated after it was extracted from NetInfo to support some new features, however, the previous API is still available and works with no updates to your code.
Internally this library has a network state manager class to handle all the functionality and state. This library provides two options for instantiating the class:
108
+
1. you can use global library functions which taps into a global singleton instance of the class
109
+
2. or you can create isolated instances of the class to tap into, each being separately configured
@@ -241,7 +265,9 @@ The configuration options for the library.
241
265
| `useNativeReachability` | `boolean` | `true` | A flag indicating whether or not Netinfo should use native reachability checks, if available.
242
266
243
267
244
-
### Methods
268
+
### Global instance methods
269
+
270
+
Please note the difference between global and isolated usage described [here](#global-vs-isolated-instance)
245
271
246
272
#### `configure()`
247
273
@@ -285,7 +311,7 @@ unsubscribe();
285
311
286
312
#### `useNetInfo()`
287
313
288
-
A [React Hook](https://reactjs.org/docs/hooks-intro.html) which can be used to get access to the latest state. It returns a hook with the [`NetInfoState`](README.md#netinfostate) type.
314
+
A [React Hook](https://reactjs.org/docs/hooks-intro.html) which can be used to get access to the latest state from the global instance. It returns a hook with the [`NetInfoState`](README.md#netinfostate) type.
This will also update subscribers using `addEventListener` and/or `useNetInfo`.
360
386
387
+
### Isolated instance
388
+
389
+
Please note the difference between global and isolated usage described [here](#global-vs-isolated-instance)
390
+
391
+
#### `useNetInfoInstance()`
392
+
393
+
A [React Hook](https://reactjs.org/docs/hooks-intro.html) which can be used to create and manage an isolated instance of a network manager class. It returns a `refresh` function and the current [`NetInfoState`](README.md#netinfostate).
**isPaused**: You can also pause the hooks internal network checks by passing a boolean value `true` as the first argument.
412
+
413
+
**configuration**: You can optionally send configuration as the second argument when setting up the hook. Note that configuration is local to the instance managed by this hook and has no relation to the configuration passed to other functions `configure()` or `useNetInfo()`;
0 commit comments