@@ -22,12 +22,19 @@ import { NetInfoProvider } from 'react-native-netinfo';
22
22
const App = () => (
23
23
< View>
24
24
< NetInfoProvider
25
- onChange= {({ isConnected }) => {
25
+ onChange= {({ isConnected, connectionInfo }) => {
26
26
console .log (isConnected);
27
+ console .log (connectionInfo);
27
28
}}
28
- render= {({ isConnected }) =>
29
+ render= {({ isConnected, connectionInfo }) =>
29
30
isConnected ? (
30
- < Text > Wonderful, you are connected! < / Text >
31
+ < React .Fragment >
32
+ < Text > Wonderful, you are connected! < / Text >
33
+ < Text > Connection type: {connectionInfo .type }< / Text >
34
+ < Text >
35
+ Effective connection type: {connectionInfo .effectiveType }
36
+ < / Text >
37
+ < / React .Fragment >
31
38
) : (
32
39
< Text > It looks like you encounter connectivity problems.< / Text >
33
40
)
@@ -37,23 +44,59 @@ const App = () => (
37
44
);
38
45
```
39
46
47
+ ### With children as a function
48
+
49
+ ``` js
50
+ import { NetInfoProvider } from ' react-native-netinfo' ;
51
+
52
+ const App = () => (
53
+ < View>
54
+ < NetInfoProvider
55
+ onChange= {({ isConnected, connectionInfo }) => {
56
+ console .log (isConnected);
57
+ console .log (connectionInfo);
58
+ }}
59
+ >
60
+ {({ isConnected, connectionInfo }) =>
61
+ isConnected ? (
62
+ < React .Fragment >
63
+ < Text > Wonderful, you are connected! < / Text >
64
+ < Text > Connection type: {connectionInfo .type }< / Text >
65
+ < Text >
66
+ Effective connection type: {connectionInfo .effectiveType }
67
+ < / Text >
68
+ < / React .Fragment >
69
+ ) : (
70
+ < Text > It looks like you encounter connectivity problems.< / Text >
71
+ )
72
+ }
73
+ < / NetInfoProvider>
74
+ < / View>
75
+ );
76
+ ```
77
+
40
78
### With component injection
41
79
42
80
``` js
43
81
import { NetInfoProvider } from ' react-native-netinfo' ;
44
82
45
- const ConnectedComponent = ({ isConnected }) =>
83
+ const ConnectedComponent = ({ isConnected, connectionInfo }) =>
46
84
isConnected ? (
47
- < Text > Wonderful, you are connected! < / Text >
85
+ < React .Fragment >
86
+ < Text > Wonderful, you are connected! < / Text >
87
+ < Text > Connection type: {connectionInfo .type }< / Text >
88
+ < Text > Effective connection type: {connectionInfo .effectiveType }< / Text >
89
+ < / React .Fragment >
48
90
) : (
49
91
< Text > It looks like you encounter connectivity problems.< / Text >
50
92
);
51
93
52
94
const App = () => (
53
95
< View>
54
96
< NetInfoProvider
55
- onChange= {({ isConnected }) => {
97
+ onChange= {({ isConnected, connectionInfo }) => {
56
98
console .log (isConnected);
99
+ console .log (connectionInfo);
57
100
}}
58
101
component= {ConnectedComponent}
59
102
/ >
@@ -62,3 +105,22 @@ const App = () => (
62
105
```
63
106
64
107
NB: you should not set both component and render props. If you were to do this, the render prop would be ignored.
108
+
109
+ ## Constants
110
+
111
+ This package also exposes constants for connection info's types and effective types.
112
+
113
+ You can use them like so:
114
+
115
+ ``` js
116
+ import { CONSTANTS } from ' react-native-netinfo' ;
117
+
118
+ const App = () => (
119
+ < View>
120
+ < Text > {CONSTANTS .CONNECTION_INFO .TYPES .WIFI }< / Text >
121
+ < Text > {CONSTANTS .CONNECTION_INFO .EFFECTIVE_TYPES [' 4G' ]}< / Text >
122
+ < / View>
123
+ );
124
+ ```
125
+
126
+ You can find the full list of types and effective types in the [ official React Native documentation about NetInfo] ( https://facebook.github.io/react-native/docs/netinfo.html#connectiontype-enum ) .
0 commit comments