32 items
AppState Foreground Detection Cleanup
Code QuizAppState & Lifecycle Mapping Across Platforms
QuizSaving State on App Lifecycle
Code QuizApp States and Transitions
QuizView Controller Lifecycle Cleanup
Code QuizBalancing View Controller Lifecycle Cleanup
QuizDetecting Backgrounding with AppState
Code QuizReact Native AppState Backgrounding
QuizWrong Method for Background Work
Code QuizUnderstanding the Inactive App State
QuizReact Native AppState & Backgrounding
Slides / VideoReact Native AppState Basics
FlashcardApp States and Background Transitions
QuizState Restoration and Cold Starts
QuizBackground Task Ends Too Early
Code QuizState Restoration Key Mismatch Bug
Code QuizuseEffect Cleanup in Mobile Apps
Slides / VideouseEffect Cleanup on Mobile
FlashcardProcess Death and State Restoration
Slides / VideoCold vs Warm Start & State Restoration
FlashcardApp State Transitions
FlashcarduseFocusEffect Re-run Bug
Code QuizView Controller Focus & Cleanup
QuizApp State Transitions Explained
Slides / VideoComponent Lifecycle & Screen Focus
Slides / VideoUIViewController Lifecycle & Focus
FlashcardSaving State on Background
Code QuizAppState Listener Cleanup Bug
Code QuiziOS App States Basics
QuizAppState & Component Lifecycle in RN
QuizAppState & Component Lifecycle in RN
Slides / VideoAppState & Component Lifecycle in RN
FlashcardAppState Foreground Detection Cleanup
Spot the subscription cleanup bug in a React Native AppState foreground/background listener.
import { useEffect, useRef } from 'react';
import { AppState, AppStateStatus } from 'react-native';
export function useOnForeground(onForeground: () => void) {
const appState = useRef<AppStateStatus>(AppState.currentState);
useEffect(() => {
const subscription = AppState.addEventListener('change', (next) => {
if (appState.current.match(/inactive|background/) && next === 'active') {
// cold/warm resume -> refresh data, revalidate session
onForeground();
}
appState.current = next;
});
return () => {
AppState.removeEventListener('change', subscription);
};
}, [onForeground]);
}This hook should fire onForeground when the app returns from background, but it has a lifecycle bug. What is wrong?