Reputation: 4050
I ask this because hitting cmd+r causes all components to be set to their default state. To replicate this with an app that was downloaded from the app store would one force close the app by double clicking the home button, swipe up on the app, and then reopen it?
I don't have any apps in the store yet so I am unable to test this.
Would saving relevant data in AsyncStorage
be a good way to preserve state after a reload?
For example: I have a logged in user whose information is saved to state. If I refresh the app, that user is lost and is forced to log back in. However, if I save the user's info to AsyncStorage
and I can restore them to state with componentDidMount
.
Upvotes: 5
Views: 1825
Reputation: 9701
Is refreshing a React Native app in the iOS simulator equivalent to closing an app and reopening it?
No. Reloading an app just makes it fetch the JS code bundle again and run it from the entry point. The native part of the application never stops. That means, if you have any custom native logic, you will not restart it. Reloading achieves in practical terms the same result as closing and opening the app.
Would saving relevant data in AsyncStorage be a good way to preserve state after a reload?
Yes. Whatever you put in the AsyncStorage
will persist reloads and also closing and opening the application again. Only by explicitly removing the data or uninstalling the application the stored data will be deleted.
Upvotes: 3