use-react-native-app-state
v0.0.2
Published
React hooks for easily using React Native's AppState
Downloads
385
Readme
use-appstate
This module makes it easy to use React Native's AppState with React Hooks.
Installation
yarn add use-appstate
Usage
useAppState
import { useAppState } from 'use-appstate';
function Component(props) {
// Possible values: "active", "background", "inactive" (iOS only)
const appState = useAppState();
// ...
}
useAppStateChange
import { useAppStateChange } from 'use-appstate';
function Component(props) {
useAppStateChange(
(status: AppStateStatus) => alert('App state changed: ' + status),
// triggers to update the callback
[props.updateCallbackWhenThisPropsChanges],
);
// ...
}
useAppStateChangedTo
import { useAppStateChangedTo } from 'use-appstate';
function Component(props) {
useAppStateChangedTo(
// Possible values: "active", "background", "inactive" (iOS only)
'active',
() => alert('App became active'),
// triggers to update the callback
[props.updateCallbackWhenThisPropsChanges],
);
// ...
}