pass props in tabs in react native

て烟熏妆下的殇ゞ 提交于 2021-02-05 12:29:37

问题


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?


回答1:


Simply Pass the state as props like this:

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

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

inside SampleComponent you can try logging it:

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

that should do it



来源:https://stackoverflow.com/questions/46719143/pass-props-in-tabs-in-react-native

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!