【问题标题】:withNavigationFocus React-Navigation alternative for class component after upgrade from 3.x to 6.x从 3.x 升级到 6.x 后类组件的 withNavigationFocus React-Navigation 替代方案
【发布时间】:2021-12-15 11:04:10
【问题描述】:
我目前正在更新我的应用程序的版本,并且我使用了一个不再存在的功能,我根据documentation尝试了几件事
但我收到“无效的挂钩调用”错误或其他错误...
没有withNavigationFocus函数的问题是屏幕渲染的时候,数据没有显示出来。我必须按 Cmd+S 来刷新并在屏幕上显示数据。知道 props 链接到 Redux。
这是导致问题的行:
export default withNavigationFocus(connect(mapStateToProps, mapDispatchToProps)(Home));
目前我找不到替代方案,有人有想法吗?
Upgrade doc link here
【问题讨论】:
标签:
react-native
react-redux
react-navigation
【解决方案1】:
您可以安装向后兼容的包,并且可以继续使用 HOC withNavigation 和 withNavigationFocus。
我npm install @react-navigation/native@^5.x @react-navigation/compat@^5.x @react-navigation/stack@^5.x
它是使用 React Navigation 5 设计的。我没有使用版本 6 进行测试