在场景中传递道具

时间:2018-04-30 06:33:41

标签: react-native react-native-router-flux

我知道react-native-router-flux可以通过Actions.key({ text: 'Test' })传递道具。想知道是否有可能在场景中传递道具?喜欢下面的东西?

<Scene
    key="page1"
    component={Page1Container}
    title="Page 1"
    props={text: 'Test'} //Anything like this in router flux?
/>

2 个答案:

答案 0 :(得分:1)

不是将引用传递给component,而是编写一个内联函数组件并传递你想要的任何道具:

<Scene
  key="page1"
  title="Page 1"
  component={sceneProps => <Page1Container {...sceneProps} text="Test" />}
/>

答案 1 :(得分:0)

或者您可以执行类似的操作

<Scene
key="login"
title="Welcome Back"
component={Login}
customProps={yourProps}
/>

在登录屏幕上

  class Login extends React.Component {

  constructor(props) {
  super(props);
  console.log(this.props.customProps);
  }
相关问题