Reputation:
I have created a Screen. in the screen I got message like "isConnected = true". Now I want to navigate to another screen only if "isConnected = true" else I want to show message like please connect to internet. so what should I write in if else
here is my code
import React, { Component } from "react";
import { View, Text, Button, Alert, Platform, alert } from "react-native";
import {useNetInfo} from "@react-native-community/netinfo";
export const NoConnection = ({navigation}) => {
const netInfo = useNetInfo();
if (condition) {
} else {
}
return (
<View>
<Text>Type: {netInfo.type}</Text>
<Text>Is Connected? {netInfo.isConnected.toString()}</Text>
</View>
);
}
Upvotes: 0
Views: 55
Reputation: 4938
You could check for the condition and navigate accordingly.
import React, { Component } from "react";
import { View, Text, Button, Alert, Platform, alert } from "react-native";
import {useNetInfo} from "@react-native-community/netinfo";
export const NoConnection = ({navigation}) => {
const netInfo = useNetInfo();
if (netInfo.isConnected) {
// navigation -> go to other screen
return null;
}
return (
<View>
<Text>Type: {netInfo.type}</Text>
<Text>Is Connected? {netInfo.isConnected.toString()}</Text>
</View>
);
}
Upvotes: 1