在 React Native 的标签中传递道具 [英] pass props in tabs in react native

查看:35
本文介绍了在 React Native 的标签中传递道具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何将状态从我的主页传递到选项卡?目前我正在使用导航将道具从一个页面转移到另一个页面,但从选项卡看来我不能这样做,你有关于如何将道具传递给选项卡的函数或示例代码吗?

I would like to know how to pass a state from my main page to the Tabs? Currently I'm using navigate to transfer props from one page to another page but from Tabs it seems I cannot do that, do you have a function or sample code on how to pass props to the Tabs?

推荐答案

像这样简单地将 state 作为 props 传递:

Simply Pass the state as props like this:

<SampleComponent 
   sampleProps={this.state.MyMainPageState} 
/>

从那里你可以在你的 SampleComponent 作为道具访问它;)

from there you can access it at your SampleComponent as props ;)

在 SampleComponent 中,您可以尝试记录它:

inside SampleComponent you can try logging it:

//this is the state from your mainPage
const {sampleProps} = this.props; 
 console.log(sampleProps); 

应该这样做

这篇关于在 React Native 的标签中传递道具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆