简体   繁体   English

无法在React Native Navigation v2中将道具传递给其他组件

[英]Unable to pass props to other components in react native navigation v2

Unable to pass props to other components in react native navigation v2. 无法将prop传递给React Native Navigation v2中的其他组件。 I am getting undefined whenever I am trying to call that props in my component. 每当我尝试在组件中调用该道具时,我都会变得不确定。 I would like to notify that I am using redux in my project and I found a similar issue in StackOverflow but it didn't work for me. 我想通知我,我在项目中使用了Redux,但我在StackOverflow中发现了类似的问题,但对我不起作用。

React Native Navigation code:- 反应本机导航代码:-

Navigation.push("FamilyStack", {
  component: {
    name: "com.radarx.FamilyFormScreen",
    passProps: {
      text: "Pushed screen"
    },
    options: {
      topBar: {
        title: {
          text: "Pushed screen title"
        }
      }
    }
  }
});

But when I am trying to use that prop it's giving me an error of type undefined. 但是,当我尝试使用该道具时,它给了我一个undefined类型的错误。

I am trying to call the prop here just for checking if it's working for not. 我试图在这里调用道具只是为了检查它是否有用。

class FamilyFormScreen extends Component {
constructor(props) {
super(props);
console.log("screen: ", props);

} }

You need to extract from the props the correct params in order to "see" the params you are passing through navigation. 您需要从道具中提取正确的参数,以便“看到”正在导航的参数。

After super(props) you should be able to call console.log("screen ", this.props) super(props)之后,您应该可以调用console.log("screen ", this.props)

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

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