1- # BuckleScript bindings to React Native NetInfo
1+ # BuckleScript bindings to ` @react-native-community/netinfo `
22
33[ ![ Version] ( https://img.shields.io/npm/v/@reason-react-native/netinfo.svg )] ( https://www.npmjs.com/@reason-react-native/netinfo )
44
5- These are BuckleScript bindings to
6- [ ` React Native NetInfo ` ] ( https://github.com/react-native-community/react-native-netinfo ) ,
7- in Reason syntax. ` NetInfo ` has been removed from the React Native core with
8- version 0.60, but as that release has breaking changes, this package is intended
9- to work with React Native 0.59.x releases as well. Accordingly, to avoid
10- namespace clashes with the ` NetInfo ` module in ` reason-react-native ` (as would
11- happen with ` open React Native ` ) and for consistency with other projects, the
12- module has been named ` ReactNativeNetInfo ` .
5+ Reason / BuckleScript bindings for
6+ [ ` @react-native-community/netinfo ` ] ( https://github.com/react-native-community/react-native-netinfo )
7+ (exposed as ` ReactNativeNetInfo ` ).
138
14- Version of these bindings follow that of the ` React Native NetInfo ` package.
15- React Native versions 0.59.x and 0.60.x are supported, however
16- [ jetifier] ( https://github.com/mikehardy/jetifier ) is required to support
17- versions 0.59.x.
9+ ## Support
1810
19- | Version | React Native version | ` npm ` package for Reason bindings |
20- | ------- | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
21- | 4.1.x | 0.60 or 0.59.x with [ jetifier] ( https://github.com/mikehardy/jetifier ) | [ ` @reason-react-native/netinfo ` ] ( https://www.npmjs.com/@reason-react-native/netinfo ) |
22- | 3.2.x | 0.59.x | [ ` reason-react-native-netinfo ` ] ( https://www.npmjs.com/package/reason-react-native-netinfo ) |
11+ ` @reason-react-native/netinfo ` X.y._ means it's compatible with
12+ ` @react-native-community/netinfo ` X.y._
2313
24- You may update your existing code using the ` NetInfo ` module of
25- ` reason-react-native ` by replacing references to the ` ReactNative.NetInfo `
26- module with ` ReactNativeNetInfo.Legacy ` . However, do note that the new API is
27- more straightforward.
14+ | version | react-native version |
15+ | ------- | -------------------- |
16+ | 4.1.0+ | 0.60.0+ |
2817
29- ## Breaking Changes
30-
31- - Moved from
32- [ sgny/reason-react-native-netinfo] ( https://github.com/sgny/reason-react-native-netinfo#readme ) .
33- ` npm ` package was previously named ` reason-react-native-netinfo ` . Please
34- update your dependencies accordingly.
35-
36- - The module is renamed to ` ReactNativeNetInfo ` (previously` CommunityNetInfo ` ).
37-
38- - Releases require use of [ jetifier] ( https://github.com/mikehardy/jetifier ) for
39- versions 0.59.x of React Native. You may continue to use
40- [ ` reason-react-native-netinfo ` ] ( https://www.npmjs.com/package/reason-react-native-netinfo )
41- version 3.2.x if you do not wish to use ` jetifier ` .
18+ For 0.59-, you should use
19+ [ ` jetify -r ` ] ( https://github.com/mikehardy/jetifier/blob/master/README.md#to-reverse-jetify--convert-node_modules-dependencies-to-support-libraries ) .
4220
4321## Installation
4422
4523With ` yarn ` :
4624
47- ``` shell
25+ ``` console
4826yarn add @reason-react-native/netinfo
4927```
5028
5129With ` npm ` :
5230
53- ``` shell
31+ ``` console
5432npm install @reason-react-native/netinfo
5533```
5634
57- Once package installation completes , ` @react-native-community/netinfo ` should be
58- linked to your project. You may use the CLI as below :
35+ If you use React Native 0.60 , ` @react-native-community/netinfo ` should be linked
36+ to your project:
5937
60- ``` shell
38+ ``` console
6139react-native link @react-native-community/netinfo
6240```
6341
6442Finally, ` @reason-react-native/netinfo ` should be added to ` bs-dependencies ` in
6543` BuckleScript ` configuration of the project (` bsconfig.json ` ). For example:
6644
67- ``` json
45+ ``` diff
6846{
69- ...
70- "bs-dependencies" : [" reason-react" , " reason-react-native" , " @reason-react-native/netinfo" ],
71- ...
47+ //...
48+ "bs-dependencies": [
49+ "reason-react",
50+ "reason-react-native",
51+ + "@reason-react-native/netinfo"
52+ ],
53+ //...
7254}
7355```
7456
75- ## Types
57+ ## Usage
58+
59+ ### Types
7660
77- ### ` netInfoStateType `
61+ #### ` netInfoStateType `
7862
7963Kind of the current network connection. Valid values are:
8064
@@ -90,7 +74,7 @@ Kind of the current network connection. Valid values are:
9074| ` vpn ` | Android | Active |
9175| ` other ` | Android, iOS, Windows | Active |
9276
93- ### ` netInfoCellularGeneration `
77+ #### ` netInfoCellularGeneration `
9478
9579Cellular generation of the current network connection. Valid values are:
9680
@@ -100,7 +84,7 @@ Cellular generation of the current network connection. Valid values are:
10084| ` net3g ` | Inlined as "3g". Returned for EHRPD, EVDO, HSPA, HSUPA, HSDPA and UTMS connections. |
10185| ` net4g ` | Inlined as "4g". Returned for HSPAP and LTE connections |
10286
103- ### ` details `
87+ #### ` details `
10488
10589``` reason
10690type details = {
@@ -110,7 +94,7 @@ type details = {
11094};
11195```
11296
113- ### ` netInfoState `
97+ #### ` netInfoState `
11498
11599``` reason
116100type netInfoState = {
@@ -133,9 +117,9 @@ If the `details` objects is not `null`, the `cellularGeneration` key within will
133117- be of type ` netInfoCellularGeneration ` only when ` _type ` is ` cellular ` and its
134118 generation can be determined.
135119
136- ## Methods
120+ ### Methods
137121
138- ### ` fetch `
122+ #### ` fetch `
139123
140124To query the connection state, returns ` netInfoState ` wrapped in a ` Promise ` .
141125
@@ -184,7 +168,7 @@ React.useEffect0(() => {
184168});
185169```
186170
187- ### ` addEventListener `
171+ #### ` addEventListener `
188172
189173To subscribe to the connection state; accepts a listener of type
190174` netInfoState => unit ` and returns an unsubscribe method of type ` unit => unit ` .
@@ -237,7 +221,7 @@ React.useEffect0(() => {
237221});
238222```
239223
240- ### ` useNetInfo `
224+ #### ` useNetInfo `
241225
242226This method returns a React Hook with type ` netInfoState `
243227
0 commit comments