[英]How to pass variable between screens in react native (see attached)
Please see snapshot attached: Code Snippet请参阅附上的快照:代码片段
I'm trying to export this variable "email" from the 'List' screen, to the 'Account' screen without having to navigate to it as it is a bottomTabNavigator.我正在尝试将此变量“电子邮件”从“列表”屏幕导出到“帐户”屏幕,而无需导航到它,因为它是一个底部标签导航器。
Any help would be very appreciated!任何帮助将不胜感激!
Here's the repo: GitHub Repo这是回购: GitHub 回购
It depends on which sort of state management are you using.这取决于您使用的是哪种 state 管理。 In case of redux you can simply have a state that you communicate between the screens or create a top level context with reducers hook to pass the data.
在 redux 的情况下,您可以简单地使用 state 在屏幕之间进行通信,或者使用减速器挂钩创建顶级上下文以传递数据。
some way you can handle that:您可以通过某种方式处理:
redux
in your project for access to your states
in all of your projectredux
以访问您所有项目中的states
for more info see this有关更多信息,请参阅此
this solution totally used in big project该解决方案完全用于大型项目
createContext
to save your some props
and you can access that in other Screen for more info see thiscreateContext
保存您的一些props
,您可以在其他屏幕中访问它以获取更多信息,请参阅此3.use global
prop in project and you can set
and get
from that 3.在项目中使用
global
道具,您可以从中set
和get
for Example for set like that:例如这样设置:
global.myProb=5;
and for get:并获得:
var m=global.myProb;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.