无需重置路线即可在本机中实时重新加载 [英] Live reload in react-native without resetting the route

查看:55
本文介绍了无需重置路线即可在本机中实时重新加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

React Native 中的 实时重新加载 功能非常简洁.但是有一个问题.当我的应用程序重新加载时——每次我更改代码时——路由被重置并导航回主屏幕.如果我正在处理五六个屏幕深的功能,这尤其令人讨厌.手动重新加载也做同样的事情.

The live reload feature in react native is neat. But there's one problem. When my app reloads--every time I change the code--the route is reset and it navigates back to the home screen. This is especially annoying if I'm working on a feature that's five or six screens deep. And reloading manually does the same thing.

有没有办法让它自动重新加载与重新加载之前相同的路线?作为比较,这在 ionic livereload 中不是问题.

Is there any way to have it automatically reload the same route it was at before the reload? As a point of comparison, this is not an issue in ionic livereload.

谢谢.

更新: HMR(热模块重新加载)随 RN 0.22 几天前,现在可以了.

Update: HMR (hot module reloading) shipped with RN 0.22 a few days ago, and this is now possible.

推荐答案

这就是实时重新加载的工作方式.它会重新加载所有 js,因此您会丢失所有状态.您可以通过将状态保存到磁盘或其他地方来绕过它,它会在重新加载后持续存在,但我建议不要这样做.我密切关注 react native 存储库中的提交,并且围绕热模块重新加载 (HMR) 进行了很多活动,它允许组件使用新的 js 重新加载自己,而无需重新加载整个应用程序.这将提供您正在寻找的确切内容.我不确定这是否会在即将发布的 0.18.0 或之后的下一个版本中发布.

This is just the way the live reload works. It reloads all the js and thus you lose all your state. You could probably hack around it by saving state to disk or somewhere else that it will persist across reloads but I would recommend against that. I keep a close eye on commits in the react native repository and there has been a lot of activity around Hot Module Reloading (HMR) which allows components to reload themselves with new js without reloading the entire app. This will give the exact thing you are looking for. I am not sure if this will land in 0.18.0 that is about to release or come out in the next release after that.

这篇关于无需重置路线即可在本机中实时重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆