简体   繁体   中英

React Native: How to prevent state variables from getting re-set on hot reload?

In my React Native app, I have several state variables that get initialized to zero in the constructor, and then updated by the user. The problem is that when I'm running the app on an emulator, whenever I save my code, the emulator hot reloads, and the constructor gets run, thereby resetting all these state variables to zero. Is there a standard way to handle this? Or should I just actually reload every time this happens, and assume this won't be a problem when I'm running the app in real life?

Thats not something you can handle it. Bundler does everything. Sometimes it resets states sometimes does not. Always remaps all bundles and patch them through the DOM and it depends on your DOM tree.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM