React Native module to detect VPN connection
npm install react-native-vpn-detectorReact Native module to detect VPN connection
To install the module, you can use npm:
``bash`You must install @react-native-community/netinfo first
npx expo install @react-native-community/netinfo
npm install react-native-vpn-detector
The VPN detector does not work on simulators. Please test on a real device.
The useIsVpnActive hook lets your component reactively track whether a VPN connection is active
`javascript
import React from "react";
import { View, Text } from "react-native";
import { useIsVpnActive } from "react-native-vpn-detector";
const App = () => {
const isVpnActive = useIsVpnActive();
return (
);
};
`
The isVpnActive function checks if a VPN connection is active.
`javascript
import React from "react";
import { View, Text } from "react-native";
import { isVpnActive } from "react-native-vpn-detector";
const value = isVpnActive();
const App = () => {
return (
);
};
`
The addEventListener function listens for changes in the VPN connection status.
`javascript
import React, { useEffect } from "react";
import { View, Text } from "react-native";
import { addEventListener } from "react-native-vpn-detector";
const App = () => {
useEffect(() => {
const listener = (isVpnActive) => {
console.log(VPN is now ${isVpnActive ? "active" : "inactive"});
};
const unsubscribe = addEventListener(listener);
return () => {
unsubscribe();
};
}, []);
return (
);
};
``
Contributions are welcome! Please open an issue or submit a pull request for any bugs or enhancements.
This project is licensed under the MIT License. See the LICENSE file for more information.