Skip to main content
InterviewHubPRO
Section Overview
Q19

Question 19 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

38%
React Native & Expo (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)

How do you handle App State changes (`AppState`)?

senior LevelCode ExampleSystem Design

In Simple Words: Tracks whether the application is in the foreground, background, or transitioning:

  • States:
    • active: App is running in the foreground and receiving user interactions.
    • background: App is minimized or user is on the home screen.
    • inactive (iOS only): App is transitioning (e.g. app switcher, incoming phone call, Control Center open).
typescript
useEffect(() => {
  const subscription = AppState.addEventListener("change", (nextState) => {
    if (nextState === "active") {
      syncLatestMessages();
    }
  });
  return () => subscription.remove();
}, []);