Home > Back-end >  how can I use navigation.navigate("Login") within the login function
how can I use navigation.navigate("Login") within the login function

Time:11-04

This is my Home page code

const HomePage = ({navigation}) =>{

    const login=()=>{
        
    }
    return(
        <View>
        <ToolBar title="Home Page"></ToolBar>
        <MyButton onPress={() => navigation.navigate("Login")} title="Register"></MyButton>
        </View>
    )
}


export default HomePage;

here I want to use the login function to onPress(). How can I do it?

CodePudding user response:

Do it like this:

const login=()=>{
    //write any logic or API call
    navigation.navigate("Login")
}

And in return call it like:

<MyButton onPress={() => login()} title="Register" />

CodePudding user response:

const HomePage = ({navigation}) =>{

const login=()=>{
    navigation.navigate("Login")
}
return(
    <View>
    <ToolBar title="Home Page"></ToolBar>
    <MyButton onPress={login} title="Register"></MyButton>
    </View>
    )
}
export default HomePage;
  • Related