import React, { useRef, useState, useEffect } from "react";import { AppState, StyleSheet, Text, View } from "react-native";const AppStateExample = () => { const appState = useRef(AppState.currentState); const [appStateVisible, setAppStateVisible] = useState(appState.current); useEffect(() => { const subscription=AppState.addEventListener("change", nextAppState=>{ if (appState.current.match(/inactive|background/) && nextAppState === "active" ) console.log("App has come to the foreground!"); appState.current = nextAppState; setAppStateVisible(appState.current); console.log("AppState", appState.current); }); return () => { subscription.remove(); }; }, []); return ( Current state is: {appStateVisible} );};const styles = StyleSheet.create({ container: { flex: 1, justifyContent: "center", alignItems: "center"},});export default AppStateExample;