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

时间:2018-12-06 06:54:28

标签: javascript reactjs react-native react-redux react-native-navigation

在本机导航v2中无法将道具传递给其他组件。每当我尝试在组件中调用该道具时,我都会变得不确定。我想通知我,我在项目中使用了Redux,但我在StackOverflow中发现了类似的问题,但对我而言不起作用。

反应本机导航代码:-

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

但是当我尝试使用该道具时,它给了我一个undefined类型的错误。

我试图在这里调用道具只是为了检查道具是否有用。

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

}

1 个答案:

答案 0 :(得分:1)

您需要从道具中提取正确的参数,以便“查看”正在导航的参数。

super(props)之后,您应该可以致电console.log("screen ", this.props)