【问题标题】:react native pass value from drawer navigator从抽屉导航器中反应本机传递值
【发布时间】:2019-03-01 02:29:55
【问题描述】:

在 App.js 中

const MyApp = createDrawerNavigator({
    Home: {
        screen: Home
    },

    Form: {
        screen: Form // how to pass value Id = 0
    },
    {
      ....
     }
})

在 Form.js 中

componentDidMount() {
    if (this.props.navigation.getParam('Id', 1) !== 0) {
        ...
    }
    else {
        ...
    }
}

谁能告诉我如何做到这一点?

提前致谢

【问题讨论】:

    标签: navigator drawer


    【解决方案1】:

    使用屏幕道具:

    const MyApp = createDrawerNavigator({
        Home: {
            screen: Home
        },
    
        Form: {
            screen: props => <Form {...props} id={0} />
        },
        {
          ....
         }
    })
    

    &lt;Form {..props} id={0} /&gt; 中,您需要使用 {...props} 传递所有道具,以便导航正常工作。

    然后,您可以从表单屏幕访问道具并根据您的用例使用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-04
      • 1970-01-01
      相关资源
      最近更新 更多