AppState

AppState can tell you if the app is in the foreground or background, and notify you when the state changes.

States: active (the app is running in the foreground), background (the app is running in the background, i.e., the user has not focused the app’s tab).

import { AppState } from 'react-native';

API

Static properties

isAvailable boolean

Whether the browser environment supports AppState.

currentState ?("active" | "background")

Returns the current state of the app.

Static methods

addEventListener (type: ?string, listener: (boolean) => void) => ?EmitterSubscription

Add a listener to AppState changes. Listen to the "change" event type. The handler is called with the app state value.


Examples

Updated
Edit
React Native for WebCopyright © Nicolas Gallagher and Meta Platforms, Inc.