简体   繁体   English

undefined 不是对象 this.props 错误

[英]undefined is not an object this.props error

I am trying to follow this ( link ) tutorial for navigating between sign up and login pages.我正在尝试按照此( 链接)教程在注册和登录页面之间导航。 Part way through it I get the error :通过它的一部分,我得到了错误:

undefined is not an object this.props undefined 不是对象 this.props

I am getting this error when I try to add the following button in Login.js :当我尝试在 Login.js 中添加以下按钮时出现此错误:

<Button
   title='Go to SignUp'
   onPress={() => this.props.navigation.navigate('SignUp')}
/>

This is before the part where the article talks about 'Managing authentication flow'.这是在文章讨论“管理身份验证流程”之前的部分。 I have implemented all the code before this section but I'm not able to proceed further.我已经实现了本节之前的所有代码,但我无法进一步进行。 Please help.请帮忙。

Here's a link to the expo snack.这是世博小吃的链接。 https://snack.expo.io/rkuPjzLRr https://snack.expo.io/rkuPjzLRr

Because there's no props in your Login (that identifier isn't declared anywhere).因为您的Login没有props (该标识符未在任何地方声明)。 Instead of代替

export default function Login() {

do

export default function Login(props) {

the problem says that he can't find navigation in the props, be sure that your component is in the stack navigator your component can't get the navigation prop without it问题是他在道具中找不到导航,请确保您的组件在堆栈导航器中,没有它,您的组件无法获得导航道具

const AuthNavigation = createStackNavigator(
  {
    Login: { screen: Login },
    Signup: { screen: Signup }
  },
  {
    initialRouteName: 'Login'
  }
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM