react-native - this.props.navigation.setParams() 不会更新之前传递的导航参数
问题描述
我在我的 react-native 项目中使用 a ,并分别TabNavigator
通过 和 在屏幕之间传递一些数据。问题是这种方法对我有用,仅当我第一次发送该数据时,第二次尝试发送数据时,离开屏幕时数据不会更新this.props.navigation.setParams()
this.props.navigation.getParam()
navigation.state.params
下面是负责接收和发送数据的代码片段
import {NavigationEvents} from 'react-navigation';
...
receiveData = () => {
if (this.props.navigation.state.params.data !== null) {
const data = this.props.navigation.getParam('data');
this.setState({data});
}
}
sendData = () => {
const {data} = this.state;
this.props.navigation.setParams({data});
}
render(){
...
<NavigationEvents
onWillFocus = {this.receiveData}
on WillBlur = {this.sendData}
/>
...
}
解决方案
检查 tabnavigator 是否正确模糊/聚焦您的选项卡。
推荐阅读
- html - Bootstrap 导航栏折叠不展开以显示菜单的链接
- python - 如何从 Python 中的字节列表中获取最后一个字节项?
- python - 有没有办法计算数据框中仅大于 0 的列中的值的平均值?
- python - Python 将 Excel .xlsx 保存为 CSV/XML 并保存样式信息以便转换回 .xsls
- c# - 如何在变量 C# 中捕获 IActionResult 方法返回的状态代码
- html - 移至样式表时未呈现 CSS
- marklogic - 如何在 Optic API 中使用 fn:contains()、fn:starts-with() 和 fn:ends-with
- node.js - 如何在NodeJS API中过滤mongoDB,检查值是否包含在数组中的对象中
- python - 如何在 conftest.py > Logger 方法中动态获取测试用例的名称
- c++ - 在类中声明变量时,'uint'在c ++中意味着什么?