AppState.addEventListener
AppState 모듈은 애플리케이션의 상태(포그라운드, 백그라운드 등)를 감지할 수 있게 해준다
useEffect(() => {
const subscription = AppState.addEventListener('change', _handleAppStateChange);
func();
return () => {
subscription.remove();
};
}, []);
const _handleAppStateChange = nextAppState => {
if (nextAppState === 'active') {
func();
}
};