react-navigation icon indicating copy to clipboard operation
react-navigation copied to clipboard

TypeError: Cannot read property 'navigation' of undefined

Open StudioAleph opened this issue 8 years ago • 4 comments

import React, { Component } from 'react'; import { Platform, StyleSheet, Text, View, TextInput, Button } from 'react-native'; import axios from 'axios'; export default class Login extends Component { constructor(props) { super(props); this.state={ UserName2:"", UserPassword2:"" } }

UserLogin = () =>{
    const {Username,UserPassword}=this.state;
	axios({
	  method:"POST",
	  url:'http://192.168.1.102/react/user_login.php',
	  data:'NameUser='+this.state.UserName2+'&PasswordUser='+this.state.UserPassword2
    }).then(function (response){
        if(response.data.Message === "Login Succesfull"){
          this.props.navigation.navigate('Profile');
        }
        else {
          console.log(response.data);
        }
    })
    .catch(function (error) {
        console.log(error);
    });
}

render() { return ( Login Form <TextInput style={styles.inputStyle} placeholder = "Username" underlineColorAndroid = "transparent" onChangeText={(UserName2)=>this.setState({UserName2})} /> <TextInput style={styles.inputStyle} secureTextEntry={true} placeholder = "Password" underlineColorAndroid = "transparent" onChangeText={(UserPassword2)=>this.setState({UserPassword2})} />

see: https://reactnavigation.org/docs/connecting-navigation-prop.html

that said, this is a question which is better suited for stackoverflow or discord. see https://reactnavigation.org/help.html for more information on how to get help.

brentvatne avatar Apr 09 '18 18:04 brentvatne

StudioAleph Do you solve it. I have the same issue.

hdamis avatar Aug 15 '18 19:08 hdamis

I solved it using this url: https://medium.com/@ashleywnj/react-navigation-cannot-read-property-navigate-of-undefined-94ff5e9d3c2a
hope it helps someone

balmun03 avatar Sep 19 '18 14:09 balmun03

https://reactnavigation.org/docs/en/with-navigation.html `import React from 'react'; import { Button } from 'react-native'; import { withNavigation } from 'react-navigation';

class MyBackButton extends React.Component { render() { return <Button title="Back" onPress={() => { this.props.navigation.goBack() }} />; } }

// withNavigation returns a component that wraps MyBackButton and passes in the // navigation prop export default withNavigation(MyBackButton);`

JaveedIshaq avatar Feb 15 '19 11:02 JaveedIshaq