Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Invalid hook call. Hooks can only be called inside of the body of a function component - error displayed when tryingto use useNavigation() to redirect

$
0
0

I am new to React native and I try to redirect after Facebook login bu I get the Invalid hook call. Hooks can only be called inside of the body of a function component . I Here is my code. Please give me some help with the issue. The login works until I try to use useNavigation().

export default function LoginScreen({ path }: { path: string }) {  return (<Container style={styles.container} ><FormControl><Button style={styles.loginButton} onPress={FacebookLogin}><Text style={styles.textButton}>Login with Facebook</Text></Button></FormControl></Container>  );}async function FacebookLogin(){  try {    await Facebook.initializeAsync({      appId: '...',    });    const data = await Facebook.logInWithReadPermissionsAsync({      permissions: ['public_profile'],    });    if (data.type === 'success') {      const response = await fetch(`https://graph.facebook.com/me?access_token=${(data.token)}`);      //type authScreenProp = StackNavigationProp<RootStackParamList, 'Dashboard'>;      // const navigation = useNavigation<authScreenProp>();      //rconsole.log(await response.json());      Alert.alert('Logged in!', `Hi ${(await response.json()).name}!`);      const navigation = useNavigation();      navigation.navigate('Dashboard');    } else {      // type === 'cancel'    }  } catch ({ message }) {    alert(`Facebook Login Error: ${message}`);  }}

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>