undefined is not an object (evaluating'_this2.props.navigation.navigate') - React Native
up vote
0
down vote
favorite
I am having trouble navigating through screens with a simple button.
This is my App.js
export default class App extends Component<Props> {
render() {
return (
<AppStackNavigator/>
);
}
}
const AppStackNavigator = StackNavigator({
Login: { screen: LoginScreen },
Home: { screen: HomeScreen },
},{
navigationOptions: {
gesturesEnabled:false
}
})
Login.js
export default class Login extends Component {
render() {
return(
<SafeAreaView style={styles.container}>
<StatusBar barStyle='light-content'/>
<KeyboardAvoidingView behavior='padding' style={styles.container}>
<TouchableWithoutFeedback style={styles.container} onPress={Keyboard.dismiss}>
<View style={styles.logoContainer}>
<View style={styles.logoContainer}>
<Image style={styles.logo}
source={require('../images/logo/logo.png')}>
</Image>
<Text style={styles.title}>
Sports Chat App
</Text>
</View>
<View style={styles.infoContainer}>
<TextInput style={styles.input}
placeholder="Enter name"
placeholderTextColor='#ffffff'
keyboardType='default'
returnKeyType='next'
autoCorrect={false}
onSubmitEditing={()=> this.refs.phoneNumber.focus()}
/>
<TextInput style={styles.input}
placeholder="Enter phone number"
placeholderTextColor='#ffffff'
keyboardType='phone-pad'
ref={'phoneNumber'}
/>
<TouchableOpacity style={styles.buttonContainer}>
<Button title='LogIn' onPress={()=>this.props.navigation.navigate('Home')}/>
</TouchableOpacity>
</View>
</View>
</TouchableWithoutFeedback>
</KeyboardAvoidingView>
</SafeAreaView>
)
}
};
LoginScreen.js
class LoginScreen extends Component {
render(){
return (
<View>
<Login>
</Login>
</View>
);
}
}
I keep getting the error undefined is not an object (evaluating'_this2.props.navigation.navigate') whenever i try use the Login button in Login.js,
I want this to navigate to the home screen but cant figure out why this keeps happening.
If i try do it without the components it works fine.
Click to View error message
react-native
add a comment |
up vote
0
down vote
favorite
I am having trouble navigating through screens with a simple button.
This is my App.js
export default class App extends Component<Props> {
render() {
return (
<AppStackNavigator/>
);
}
}
const AppStackNavigator = StackNavigator({
Login: { screen: LoginScreen },
Home: { screen: HomeScreen },
},{
navigationOptions: {
gesturesEnabled:false
}
})
Login.js
export default class Login extends Component {
render() {
return(
<SafeAreaView style={styles.container}>
<StatusBar barStyle='light-content'/>
<KeyboardAvoidingView behavior='padding' style={styles.container}>
<TouchableWithoutFeedback style={styles.container} onPress={Keyboard.dismiss}>
<View style={styles.logoContainer}>
<View style={styles.logoContainer}>
<Image style={styles.logo}
source={require('../images/logo/logo.png')}>
</Image>
<Text style={styles.title}>
Sports Chat App
</Text>
</View>
<View style={styles.infoContainer}>
<TextInput style={styles.input}
placeholder="Enter name"
placeholderTextColor='#ffffff'
keyboardType='default'
returnKeyType='next'
autoCorrect={false}
onSubmitEditing={()=> this.refs.phoneNumber.focus()}
/>
<TextInput style={styles.input}
placeholder="Enter phone number"
placeholderTextColor='#ffffff'
keyboardType='phone-pad'
ref={'phoneNumber'}
/>
<TouchableOpacity style={styles.buttonContainer}>
<Button title='LogIn' onPress={()=>this.props.navigation.navigate('Home')}/>
</TouchableOpacity>
</View>
</View>
</TouchableWithoutFeedback>
</KeyboardAvoidingView>
</SafeAreaView>
)
}
};
LoginScreen.js
class LoginScreen extends Component {
render(){
return (
<View>
<Login>
</Login>
</View>
);
}
}
I keep getting the error undefined is not an object (evaluating'_this2.props.navigation.navigate') whenever i try use the Login button in Login.js,
I want this to navigate to the home screen but cant figure out why this keeps happening.
If i try do it without the components it works fine.
Click to View error message
react-native
try adding a constructor in your login.jsconstructor(props){ super(props) }
– Ziyo
Nov 12 at 1:01
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am having trouble navigating through screens with a simple button.
This is my App.js
export default class App extends Component<Props> {
render() {
return (
<AppStackNavigator/>
);
}
}
const AppStackNavigator = StackNavigator({
Login: { screen: LoginScreen },
Home: { screen: HomeScreen },
},{
navigationOptions: {
gesturesEnabled:false
}
})
Login.js
export default class Login extends Component {
render() {
return(
<SafeAreaView style={styles.container}>
<StatusBar barStyle='light-content'/>
<KeyboardAvoidingView behavior='padding' style={styles.container}>
<TouchableWithoutFeedback style={styles.container} onPress={Keyboard.dismiss}>
<View style={styles.logoContainer}>
<View style={styles.logoContainer}>
<Image style={styles.logo}
source={require('../images/logo/logo.png')}>
</Image>
<Text style={styles.title}>
Sports Chat App
</Text>
</View>
<View style={styles.infoContainer}>
<TextInput style={styles.input}
placeholder="Enter name"
placeholderTextColor='#ffffff'
keyboardType='default'
returnKeyType='next'
autoCorrect={false}
onSubmitEditing={()=> this.refs.phoneNumber.focus()}
/>
<TextInput style={styles.input}
placeholder="Enter phone number"
placeholderTextColor='#ffffff'
keyboardType='phone-pad'
ref={'phoneNumber'}
/>
<TouchableOpacity style={styles.buttonContainer}>
<Button title='LogIn' onPress={()=>this.props.navigation.navigate('Home')}/>
</TouchableOpacity>
</View>
</View>
</TouchableWithoutFeedback>
</KeyboardAvoidingView>
</SafeAreaView>
)
}
};
LoginScreen.js
class LoginScreen extends Component {
render(){
return (
<View>
<Login>
</Login>
</View>
);
}
}
I keep getting the error undefined is not an object (evaluating'_this2.props.navigation.navigate') whenever i try use the Login button in Login.js,
I want this to navigate to the home screen but cant figure out why this keeps happening.
If i try do it without the components it works fine.
Click to View error message
react-native
I am having trouble navigating through screens with a simple button.
This is my App.js
export default class App extends Component<Props> {
render() {
return (
<AppStackNavigator/>
);
}
}
const AppStackNavigator = StackNavigator({
Login: { screen: LoginScreen },
Home: { screen: HomeScreen },
},{
navigationOptions: {
gesturesEnabled:false
}
})
Login.js
export default class Login extends Component {
render() {
return(
<SafeAreaView style={styles.container}>
<StatusBar barStyle='light-content'/>
<KeyboardAvoidingView behavior='padding' style={styles.container}>
<TouchableWithoutFeedback style={styles.container} onPress={Keyboard.dismiss}>
<View style={styles.logoContainer}>
<View style={styles.logoContainer}>
<Image style={styles.logo}
source={require('../images/logo/logo.png')}>
</Image>
<Text style={styles.title}>
Sports Chat App
</Text>
</View>
<View style={styles.infoContainer}>
<TextInput style={styles.input}
placeholder="Enter name"
placeholderTextColor='#ffffff'
keyboardType='default'
returnKeyType='next'
autoCorrect={false}
onSubmitEditing={()=> this.refs.phoneNumber.focus()}
/>
<TextInput style={styles.input}
placeholder="Enter phone number"
placeholderTextColor='#ffffff'
keyboardType='phone-pad'
ref={'phoneNumber'}
/>
<TouchableOpacity style={styles.buttonContainer}>
<Button title='LogIn' onPress={()=>this.props.navigation.navigate('Home')}/>
</TouchableOpacity>
</View>
</View>
</TouchableWithoutFeedback>
</KeyboardAvoidingView>
</SafeAreaView>
)
}
};
LoginScreen.js
class LoginScreen extends Component {
render(){
return (
<View>
<Login>
</Login>
</View>
);
}
}
I keep getting the error undefined is not an object (evaluating'_this2.props.navigation.navigate') whenever i try use the Login button in Login.js,
I want this to navigate to the home screen but cant figure out why this keeps happening.
If i try do it without the components it works fine.
Click to View error message
react-native
react-native
edited Nov 12 at 11:25
asked Nov 11 at 16:46
Liam Ramsbottom
12
12
try adding a constructor in your login.jsconstructor(props){ super(props) }
– Ziyo
Nov 12 at 1:01
add a comment |
try adding a constructor in your login.jsconstructor(props){ super(props) }
– Ziyo
Nov 12 at 1:01
try adding a constructor in your login.js
constructor(props){ super(props) }
– Ziyo
Nov 12 at 1:01
try adding a constructor in your login.js
constructor(props){ super(props) }
– Ziyo
Nov 12 at 1:01
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
App.js
import React, { Component } from "react";
import { Text, View } from "react-native";
import AppStackNavigator from "./AppStackNavigator";
export default class App extends Component<Props> {
render() {
return <AppStackNavigator />;
}
}
AppStackNavigator
import React, { Component } from "react";
import { StackNavigator } from "react-navigation";
import { View, Text, TouchableOpacity } from "react-native";
const LoginScreen = props => (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<Login navigation={props.navigation} />
</View>
);
const HomeScreen = () => (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<Text>Home</Text>
</View>
);
const Login = props => (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<TouchableOpacity
onPress={() => {
props.navigation.navigate("Home");
}}
>
<Text>GO to home from login</Text>
</TouchableOpacity>
</View>
);
export default (AppStackNavigator = StackNavigator(
{
Login: { screen: LoginScreen },
Home: { screen: HomeScreen }
},
{
headerMode: "none",
navigationOptions: {
gesturesEnabled: false
}
}
));
i added this to the LoginScreen and still no change, i also tired adding the constructor to the Login.js. same error keeps coming up
– Liam Ramsbottom
Nov 12 at 10:11
I have edited my answer, can you check if that helps ? @LiamRamsbottom
– mosabbir tuhin
Nov 12 at 10:44
No I keep getting the same error. I think the problem is in the Login.js file, the emulator is pointing me towards the onPress function. I have edited the above question to add the emulator screen
– Liam Ramsbottom
Nov 12 at 11:24
Replace your LoginScreen.js render with below code mentioned by @Ian Zhong - Thanks
– mosabbir tuhin
Nov 12 at 12:21
I tried getting rid of the button in Login.js and have the touchableOpacity as follows.
– Liam Ramsbottom
Nov 12 at 12:52
|
show 4 more comments
up vote
0
down vote
Add a navigation props to Login
in LoginScreen.js
, Because LoginScreen
has props navigation
but Login
don't.
render(){
return (
<View>
<Login navigation ={this.props.navigation}>
</Login>
</View>
);
}
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
App.js
import React, { Component } from "react";
import { Text, View } from "react-native";
import AppStackNavigator from "./AppStackNavigator";
export default class App extends Component<Props> {
render() {
return <AppStackNavigator />;
}
}
AppStackNavigator
import React, { Component } from "react";
import { StackNavigator } from "react-navigation";
import { View, Text, TouchableOpacity } from "react-native";
const LoginScreen = props => (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<Login navigation={props.navigation} />
</View>
);
const HomeScreen = () => (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<Text>Home</Text>
</View>
);
const Login = props => (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<TouchableOpacity
onPress={() => {
props.navigation.navigate("Home");
}}
>
<Text>GO to home from login</Text>
</TouchableOpacity>
</View>
);
export default (AppStackNavigator = StackNavigator(
{
Login: { screen: LoginScreen },
Home: { screen: HomeScreen }
},
{
headerMode: "none",
navigationOptions: {
gesturesEnabled: false
}
}
));
i added this to the LoginScreen and still no change, i also tired adding the constructor to the Login.js. same error keeps coming up
– Liam Ramsbottom
Nov 12 at 10:11
I have edited my answer, can you check if that helps ? @LiamRamsbottom
– mosabbir tuhin
Nov 12 at 10:44
No I keep getting the same error. I think the problem is in the Login.js file, the emulator is pointing me towards the onPress function. I have edited the above question to add the emulator screen
– Liam Ramsbottom
Nov 12 at 11:24
Replace your LoginScreen.js render with below code mentioned by @Ian Zhong - Thanks
– mosabbir tuhin
Nov 12 at 12:21
I tried getting rid of the button in Login.js and have the touchableOpacity as follows.
– Liam Ramsbottom
Nov 12 at 12:52
|
show 4 more comments
up vote
0
down vote
App.js
import React, { Component } from "react";
import { Text, View } from "react-native";
import AppStackNavigator from "./AppStackNavigator";
export default class App extends Component<Props> {
render() {
return <AppStackNavigator />;
}
}
AppStackNavigator
import React, { Component } from "react";
import { StackNavigator } from "react-navigation";
import { View, Text, TouchableOpacity } from "react-native";
const LoginScreen = props => (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<Login navigation={props.navigation} />
</View>
);
const HomeScreen = () => (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<Text>Home</Text>
</View>
);
const Login = props => (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<TouchableOpacity
onPress={() => {
props.navigation.navigate("Home");
}}
>
<Text>GO to home from login</Text>
</TouchableOpacity>
</View>
);
export default (AppStackNavigator = StackNavigator(
{
Login: { screen: LoginScreen },
Home: { screen: HomeScreen }
},
{
headerMode: "none",
navigationOptions: {
gesturesEnabled: false
}
}
));
i added this to the LoginScreen and still no change, i also tired adding the constructor to the Login.js. same error keeps coming up
– Liam Ramsbottom
Nov 12 at 10:11
I have edited my answer, can you check if that helps ? @LiamRamsbottom
– mosabbir tuhin
Nov 12 at 10:44
No I keep getting the same error. I think the problem is in the Login.js file, the emulator is pointing me towards the onPress function. I have edited the above question to add the emulator screen
– Liam Ramsbottom
Nov 12 at 11:24
Replace your LoginScreen.js render with below code mentioned by @Ian Zhong - Thanks
– mosabbir tuhin
Nov 12 at 12:21
I tried getting rid of the button in Login.js and have the touchableOpacity as follows.
– Liam Ramsbottom
Nov 12 at 12:52
|
show 4 more comments
up vote
0
down vote
up vote
0
down vote
App.js
import React, { Component } from "react";
import { Text, View } from "react-native";
import AppStackNavigator from "./AppStackNavigator";
export default class App extends Component<Props> {
render() {
return <AppStackNavigator />;
}
}
AppStackNavigator
import React, { Component } from "react";
import { StackNavigator } from "react-navigation";
import { View, Text, TouchableOpacity } from "react-native";
const LoginScreen = props => (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<Login navigation={props.navigation} />
</View>
);
const HomeScreen = () => (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<Text>Home</Text>
</View>
);
const Login = props => (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<TouchableOpacity
onPress={() => {
props.navigation.navigate("Home");
}}
>
<Text>GO to home from login</Text>
</TouchableOpacity>
</View>
);
export default (AppStackNavigator = StackNavigator(
{
Login: { screen: LoginScreen },
Home: { screen: HomeScreen }
},
{
headerMode: "none",
navigationOptions: {
gesturesEnabled: false
}
}
));
App.js
import React, { Component } from "react";
import { Text, View } from "react-native";
import AppStackNavigator from "./AppStackNavigator";
export default class App extends Component<Props> {
render() {
return <AppStackNavigator />;
}
}
AppStackNavigator
import React, { Component } from "react";
import { StackNavigator } from "react-navigation";
import { View, Text, TouchableOpacity } from "react-native";
const LoginScreen = props => (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<Login navigation={props.navigation} />
</View>
);
const HomeScreen = () => (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<Text>Home</Text>
</View>
);
const Login = props => (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<TouchableOpacity
onPress={() => {
props.navigation.navigate("Home");
}}
>
<Text>GO to home from login</Text>
</TouchableOpacity>
</View>
);
export default (AppStackNavigator = StackNavigator(
{
Login: { screen: LoginScreen },
Home: { screen: HomeScreen }
},
{
headerMode: "none",
navigationOptions: {
gesturesEnabled: false
}
}
));
edited Nov 12 at 10:43
answered Nov 12 at 7:07
mosabbir tuhin
14
14
i added this to the LoginScreen and still no change, i also tired adding the constructor to the Login.js. same error keeps coming up
– Liam Ramsbottom
Nov 12 at 10:11
I have edited my answer, can you check if that helps ? @LiamRamsbottom
– mosabbir tuhin
Nov 12 at 10:44
No I keep getting the same error. I think the problem is in the Login.js file, the emulator is pointing me towards the onPress function. I have edited the above question to add the emulator screen
– Liam Ramsbottom
Nov 12 at 11:24
Replace your LoginScreen.js render with below code mentioned by @Ian Zhong - Thanks
– mosabbir tuhin
Nov 12 at 12:21
I tried getting rid of the button in Login.js and have the touchableOpacity as follows.
– Liam Ramsbottom
Nov 12 at 12:52
|
show 4 more comments
i added this to the LoginScreen and still no change, i also tired adding the constructor to the Login.js. same error keeps coming up
– Liam Ramsbottom
Nov 12 at 10:11
I have edited my answer, can you check if that helps ? @LiamRamsbottom
– mosabbir tuhin
Nov 12 at 10:44
No I keep getting the same error. I think the problem is in the Login.js file, the emulator is pointing me towards the onPress function. I have edited the above question to add the emulator screen
– Liam Ramsbottom
Nov 12 at 11:24
Replace your LoginScreen.js render with below code mentioned by @Ian Zhong - Thanks
– mosabbir tuhin
Nov 12 at 12:21
I tried getting rid of the button in Login.js and have the touchableOpacity as follows.
– Liam Ramsbottom
Nov 12 at 12:52
i added this to the LoginScreen and still no change, i also tired adding the constructor to the Login.js. same error keeps coming up
– Liam Ramsbottom
Nov 12 at 10:11
i added this to the LoginScreen and still no change, i also tired adding the constructor to the Login.js. same error keeps coming up
– Liam Ramsbottom
Nov 12 at 10:11
I have edited my answer, can you check if that helps ? @LiamRamsbottom
– mosabbir tuhin
Nov 12 at 10:44
I have edited my answer, can you check if that helps ? @LiamRamsbottom
– mosabbir tuhin
Nov 12 at 10:44
No I keep getting the same error. I think the problem is in the Login.js file, the emulator is pointing me towards the onPress function. I have edited the above question to add the emulator screen
– Liam Ramsbottom
Nov 12 at 11:24
No I keep getting the same error. I think the problem is in the Login.js file, the emulator is pointing me towards the onPress function. I have edited the above question to add the emulator screen
– Liam Ramsbottom
Nov 12 at 11:24
Replace your LoginScreen.js render with below code mentioned by @Ian Zhong - Thanks
– mosabbir tuhin
Nov 12 at 12:21
Replace your LoginScreen.js render with below code mentioned by @Ian Zhong - Thanks
– mosabbir tuhin
Nov 12 at 12:21
I tried getting rid of the button in Login.js and have the touchableOpacity as follows.
– Liam Ramsbottom
Nov 12 at 12:52
I tried getting rid of the button in Login.js and have the touchableOpacity as follows.
– Liam Ramsbottom
Nov 12 at 12:52
|
show 4 more comments
up vote
0
down vote
Add a navigation props to Login
in LoginScreen.js
, Because LoginScreen
has props navigation
but Login
don't.
render(){
return (
<View>
<Login navigation ={this.props.navigation}>
</Login>
</View>
);
}
add a comment |
up vote
0
down vote
Add a navigation props to Login
in LoginScreen.js
, Because LoginScreen
has props navigation
but Login
don't.
render(){
return (
<View>
<Login navigation ={this.props.navigation}>
</Login>
</View>
);
}
add a comment |
up vote
0
down vote
up vote
0
down vote
Add a navigation props to Login
in LoginScreen.js
, Because LoginScreen
has props navigation
but Login
don't.
render(){
return (
<View>
<Login navigation ={this.props.navigation}>
</Login>
</View>
);
}
Add a navigation props to Login
in LoginScreen.js
, Because LoginScreen
has props navigation
but Login
don't.
render(){
return (
<View>
<Login navigation ={this.props.navigation}>
</Login>
</View>
);
}
answered Nov 12 at 12:04
Ian Zhong
44919
44919
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250939%2fundefined-is-not-an-object-evaluating-this2-props-navigation-navigate-reac%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
try adding a constructor in your login.js
constructor(props){ super(props) }
– Ziyo
Nov 12 at 1:01