i want to use service in react-native using native modules ,if Wifi connectivity change from off to on just show toast that connection change
Asked
Active
Viewed 192 times
1 Answers
0
You can use react-native-netinfo plugin. Install this plugin and then add below code to your file :
import NetInfo from '@react-native-community/netinfo';
...
...
class App extends Component {
netInfoHandler;
constructor(props) {
super(props);
this.state = {
isConnected: true
}
}
componentDidMount = () => {
this.netInfoHandler = NetInfo.addEventListener(async (state) => {
if (this.state.isConnected !== state.isConnected) {
this.setState({ isConnected: state.isConnected });
// show toast here
}
});
}
componentWillUnmount = () => {
this.netInfoHandler();
}
render() {
return (
...
// your view
)
}
}
export default App

Kishan Bharda
- 5,446
- 3
- 30
- 57
-
can you use this code in native modules for android? – Majid Aziz Oct 08 '19 at 12:01
-
can u please fix this https://stackoverflow.com/questions/58267236/network-native-module-android-not-working-in-react-native-progam-for-android-whi – Majid Aziz Oct 08 '19 at 12:04