android - React Native Android:每次获得焦点时重新渲染屏幕
问题描述
我尝试使用建议的方法,例如使用forceUpdate()
方法和设置状态,但我意识到所有这些都需要先按下按钮。我也尝试forceUpdate()
从构造函数调用该方法,但这警告组件尚未渲染。如何自动重新加载屏幕?
解决方案
如果您使用反应导航,则可以在重新访问屏幕时使用焦点事件侦听器:
React.useEffect(() => {
const unsubscribe = navigation.addListener('focus', () => {
// The screen is focused
// Call any action
});
// Return the function to unsubscribe from the event so it gets removed on unmount
return unsubscribe;
}, [navigation]);
推荐阅读
- kubernetes - RabbitMQ 通用服务器 rabbit_connection_tracking 终止
- excel - Sumif 或 Sumproduct 的标准不包含特定的十进制数
- r - 在 dplyr 中的行 group by 以改变列
- angular - 如何设置表单输入字段的值并重新检查其表单验证错误
- sql - 即使我们正在分配日期时间对象,如何获取 sql 时间日期变量仅打印日期部分
- javascript - 使用 Geolocation [Onclick] 更新 Geojson 文件
- ios - 防止 UITextField 在键入时更改宽度
- javascript - 我的问题是关于使用 Nuxt.js 和 Wordpress 作为我的 Headless CMS
- java - 乌尔都语到乌尔都语使用 SpeechRecognizer 和 RecognitionListener
- c# - Xamarin.Andriod:如何从收件箱中删除或标记为已读消息(对话)