Skip to content

Instantly share code, notes, and snippets.

@vaibhavgehani
Created August 25, 2022 10:49
Show Gist options
  • Save vaibhavgehani/c09db5d14e01633e7bb822ce846a7383 to your computer and use it in GitHub Desktop.
Save vaibhavgehani/c09db5d14e01633e7bb822ce846a7383 to your computer and use it in GitHub Desktop.
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