【问题标题】:How to pass a parameter in react native navigator?如何在反应本机导航器中传递参数?
【发布时间】:2017-05-07 08:15:09
【问题描述】:

我尝试了一个 React Native Navigator 的示例:

const StudentStackNav = StackNavigator({
  Home: {
     screen: StudentLogin,
    }
});

如何将参数传递给 StudentStackNav 并将其传递给 StudentLogin?

我尝试过<StudentStackNav name='Lucy'>,但this.props.nameHome 中不可用。

【问题讨论】:

标签: reactjs react-native react-navigation


【解决方案1】:

Navigator 组件上的普通 props 可用于配置导航器。

要将任意道具发送到屏幕,您必须使用screenProps

例如:

<StudentStackNav screenProps={{ name: 'Lucy' }}/>

这将在StudentLogin 中作为this.props.screenProps 提供。

screenProps 记录在 this page

【讨论】:

  • 这个答案是正确的,并且比 react native 站点上的文档有用得多。请注意,即使似乎很少有人这样做,您也可以从类中的构造函数访问这些属性:class Foo extends Component { constructor(props) { super(props); props.screenProps // what you want to access } render() { return null; } }
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-08
  • 2022-10-16
  • 1970-01-01
  • 1970-01-01
  • 2021-12-11
  • 2021-06-24
相关资源
最近更新 更多