Home > front end >  React-native app: navigation.navigate is not a function
React-native app: navigation.navigate is not a function

Time:08-24

(In 'navigation.navigate("Home")', 'navigation.navigate' is undefined)

const handleLogin = () => {
    auth
      .signInWithEmailAndPassword(email, password)
      .then((userCredentials) => {
        const user = userCredentials.user;
        console.log("Logged in with:", user.email);
        navigation.navigate("Home");
      })
      .catch((error) => alert(error.message));
  };

How can I fix this? I want to make it so that when I press the Login button, user is identified and then I go from login screen to home screen.

CodePudding user response:

First you need to create navigation object by useNavigation hook like this.

const navigation = useNavigation()

For using useNavigation you need to install @react-navigation/native

npm i @react-navigation/native

Then import useNavigation from @react-navigation/native

import {useNavigation} from '@react-navigation/native'

Then you can navigate easily

const navigation = useNavigation()
navigation.navigate("Home")
  • Related