The average mobile device user has several apps that they use on a regular basis. Ideally, along with the other social media apps, games, media players, and more, users will also be using your React Native app. Any specific user may spend a short time in each application because he or she multitasks. What if we wanted to react to when the user leaves our app and re-enters? We could use this as a chance to sync data with the server, or to tell the user that we're happy to see them return, or to politely ask for a rating on the app store.
This recipe will cover the basics of reacting to changes in the state of the application, which is to say reacting to when the app is in the foreground (active), background, or inactive.
For this recipe, let's create a new pure React Native app titled AppStateApp.