Created
August 25, 2022 10:49
-
-
Save vaibhavgehani/c09db5d14e01633e7bb822ce846a7383 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { AppState, View, Text } from 'react-native'; | |
const App = () => { | |
const appState = useRef(AppState.currentState); | |
const [appStateVisible, setAppStateVisible] = useState(appState.current); | |
useEffect(() => { | |
console.log(appStateVisible); | |
const subscription = AppState.addEventListener("change", nextAppState => { | |
appState.current = nextAppState; | |
setAppStateVisible(appState.current); | |
}); | |
return () => { | |
subscription.remove(); | |
}; | |
}, []); | |
return ( | |
<View> | |
<Text>App State: {appStateVisible}</Text> | |
</View> | |
) | |
}; | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment