
Security News
Software Engineering Daily Podcast: Feross on AI, Open Source, and Supply Chain Risk
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.
@reason-react-native/netinfo
Advanced tools
[](https://www.npmjs.com/@reason-react-native/netinfo)
@react-native-community/netinfoReason / BuckleScript bindings for
@react-native-community/netinfo
(exposed as ReactNativeNetInfo).
@reason-react-native/netinfo X.y._ means it's compatible with
@react-native-community/netinfo X.y._
| version | react-native version |
|---|---|
| 4.1.0+ | 0.60.0+ |
For 0.59-, you should use
jetify -r.
With yarn:
yarn add @reason-react-native/netinfo
With npm:
npm install @reason-react-native/netinfo
If you use React Native 0.60, @react-native-community/netinfo should be linked
to your project:
react-native link @react-native-community/netinfo
Finally, @reason-react-native/netinfo should be added to bs-dependencies in
BuckleScript configuration of the project (bsconfig.json). For example:
{
//...
"bs-dependencies": [
"reason-react",
"reason-react-native",
+ "@reason-react-native/netinfo"
],
//...
}
netInfoStateTypeKind of the current network connection. Valid values are:
| Value | Platforms | Connection State |
|---|---|---|
none | Android, iOS, Windows | Not active |
unknown | Android, iOS, Windows | Undetermined |
cellular | Android, iOS, Windows | Active |
wifi | Android, iOS, Windows | Active |
bluetooth | Android | Active |
ethernet | Android, Windows | Active |
wimax | Android | Active |
vpn | Android | Active |
other | Android, iOS, Windows | Active |
netInfoCellularGenerationCellular generation of the current network connection. Valid values are:
| Value | Notes |
|---|---|
net2g | Inlined as "2g". Returned for CDMA, EDGE, GPRS and IDEN connections |
net3g | Inlined as "3g". Returned for EHRPD, EVDO, HSPA, HSUPA, HSDPA and UTMS connections. |
net4g | Inlined as "4g". Returned for HSPAP and LTE connections |
detailstype details = {
.
"isConnectionExpensive": bool,
"cellularGeneration": Js.Nullable.t(netInfoCellularGeneration),
};
netInfoStatetype netInfoState = {
.
"_type": netInfoStateType,
"isConnected": bool,
"details": Js.Null.t(details),
};
details key will have value Js.Null.empty (null) when _type is null or
unknown.
If the details objects is not null, the cellularGeneration key within will
Js.Nullable.undefined when _type is wifi, bluetooth,
ethernet, wimax, vpn or other.Js.Nullable.null if the connection is not cellular or its
generation cannot be determined.netInfoCellularGeneration only when _type is cellular and its
generation can be determined.fetchTo query the connection state, returns netInfoState wrapped in a Promise.
fetch: unit => Js.Promise.t(netInfoState) = "";
Below example demonstrates determination of the cellular connection generation, using this method.
React.useEffect0(() => {
Js.Promise.(
ReactNativeNetInfo.fetch()
|> then_(w =>
{
switch (w##details->Js.Null.toOption) {
| None => "Connection type is none or unknown"->Js.Console.warn
| Some(x) =>
let y = x##cellularGeneration;
switch (y->Js.Nullable.toOption) {
| None =>
if (y == Js.Nullable.undefined) {
"Connection type is wifi, bluetooth, ethernet, wimax, vpn or other"
->Js.Console.warn;
} else {
"Connection generation unknown"->Js.Console.warn;
}
| Some(z) =>
if (z == ReactNativeNetInfo.net2G) {
"2G connection"->Js.Console.warn;
} else if (z == ReactNativeNetInfo.net3G) {
"3G connection"->Js.Console.warn;
} else {
"4G connection"->Js.Console.warn;
}
};
};
}
->resolve
)
|> catch(err => "error"->Js.Console.warn->resolve)
|> ignore
);
None;
});
addEventListenerTo subscribe to the connection state; accepts a listener of type
netInfoState => unit and returns an unsubscribe method of type unit => unit.
The listener will be called once following subscription and each time connection
state changes.
addEventListener: (netInfoState => unit) => t;
where
type t = unit => unit
Below example demonstrates subscribing to changes in connection state:
React.useEffect0(() => {
let remove =
ReactNativeNetInfo.addEventListener(w =>
(
switch (w##details->Js.Null.toOption) {
| None => "Connection type is none or unknown"
| Some(x) =>
let y = x##cellularGeneration;
switch (y->Js.Nullable.toOption) {
| None =>
if (y == Js.Nullable.undefined) {
"Connection type is wifi, bluetooth, ethernet, wimax, vpn or other";
} else {
"Connection generation unknown";
}
| Some(z) =>
if (z == ReactNativeNetInfo.net2G) {
"2G connection";
} else if (z == ReactNativeNetInfo.net3G) {
"3G connection";
} else {
"4G connection";
}
};
}
)
->Js.Console.warn
);
Js.Console.warn(remove);
Some(() => remove());
});
useNetInfoThis method returns a React Hook with type netInfoState
useNetInfo: unit => netInfoState
Below example demonstrates its use within a Text component:
<Text>
(
switch (ReactNativeNetInfo.useNetInfo()##details->Js.Null.toOption) {
| None => "Connection type is none or unknown"
| Some(x) =>
let y = x##cellularGeneration;
switch (y->Js.Nullable.toOption) {
| None =>
if (y == Js.Nullable.undefined) {
"Connection type is wifi, bluetooth, ethernet, wimax, vpn or other";
} else {
"Connection generation unknown";
}
| Some(z) =>
if (z == ReactNativeNetInfo.net2G) {
"2G connection";
} else if (z == ReactNativeNetInfo.net3G) {
"3G connection";
} else {
"4G connection";
}
};
}
)
->React.string
</Text>
FAQs
ReScript bindings for @react-native-community/netinfo.
The npm package @reason-react-native/netinfo receives a total of 0 weekly downloads. As such, @reason-react-native/netinfo popularity was classified as not popular.
We found that @reason-react-native/netinfo demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.

Security News
GitHub has revoked npm classic tokens for publishing; maintainers must migrate, but OpenJS warns OIDC trusted publishing still has risky gaps for critical projects.

Security News
Rust’s crates.io team is advancing an RFC to add a Security tab that surfaces RustSec vulnerability and unsoundness advisories directly on crate pages.