reactjs - React Native 在两个屏幕中的两个类组件之间传递数据
问题描述
我有screen1和screen2。在 screen1 中,我有一个类组件 A。在 screen2 中,我有一个类组件 B。在 A 中,我有状态“分数”,我想将其传递给 screen2 中的 B。
我试过了:
在屏幕 1 中:
this.props.navigation.navigate('screen2', {
score: [this.state.score],
});
在屏幕 2 中:
const data = this.props.navigation.getParam('score');
这没用。我认为这是因为 react-navigation 已更新。
- 我查找了https://reactnavigation.org/docs/params/,但示例是函数,而不是类组件。
太感谢了!
解决方案
在较新的版本中,react-navigation
您可以访问传递给screen2
类组件的道具,如下所示:
this.props.route.params.score
推荐阅读
- python - Discord.py 机器人不阅读其他机器人的消息
- ruby-on-rails - 巫术认证系统不工作,找不到动作
- python - Pandas DataFrame,计算满足条件的一行与另一行之间的时间差
- c# - 从 Oracle SP 的数组表参数返回数据
- lotus-notes - Lotus Notes 部署
- python - 如何从另一个文件更新变量
- stripe-payments - Laravel 5.6 - 条纹错误:您没有设置有效的可发布密钥
- javascript - 如何在 React 的嵌套组件场景中使页脚与中心对齐
- dask - 有没有办法在脚本中为 Dask YarnCluster 更新而不是覆盖 worker_env?
- asp.net-mvc - 实体框架更新后缺少某些对象值