Home > Mobile >  Starting from the screen where you left off after exiting the application -RN
Starting from the screen where you left off after exiting the application -RN

Time:10-21

I'm new to React Native. I have prepared an application with 5 screens. For example, the user is on the 5th screen and exit the application. When user re-enter the application, I want it to start on the 5th screen again. I'm also trying to protect the user's states on the 5th screen. How can i do that in RN?

CodePudding user response:

React-Native has an api called AsyncStorage to help you with that.

It allows you to store data locally on the device and retrieve it when you need it, even when the app has been closed. You can find the package here: AsyncStorage

You can use it for you app to store the navigation state & 5th screen state and use that to set the states when the user (re-)opens your app.

In case you're using React-Navigation, they have a section in there docs you can follow: https://reactnavigation.org/docs/state-persistence/

CodePudding user response:

Under componentDidMount/useEffect update the last seen screen name in async storage. And navigate to last seen screen name on app open.

  • Related