How long does redux state persist in memory in react native

大憨熊 提交于 2019-12-12 12:22:22

问题


I am trying to understand how to manage redux state in my react-native app. In particular, I am trying to work out what happens when my app is minimized or the device is turned off.

With this knowledge I can then work out best how to persist state, and prepare for any illegal states that may arise from the redux state being reset.

Is it a fair assumption to make that if the redux state is reset, the entire app itself will restart (and therefore any initialization of the redux store will be called again?).


回答1:


Is it a fair assumption to make that if the redux state is reset, the entire app itself will restart

This assumption is not true, however the inverse is. The redux state can be reset during runtime if there is code to do it via a reset action or otherwise.

However if the app is shut down, and the code re-runs it will be loaded with your default redux state.

AsyncStorage (in native) / localstorage for web, is often used in conjunction with redux in order to persist state across app crashes / browser sessions.

You can set AsyncStorage as a strategy for the redux-persist middleware (or write your own)



来源:https://stackoverflow.com/questions/46207962/how-long-does-redux-state-persist-in-memory-in-react-native

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!