0.0.2 • Published 4 years ago

use-react-native-app-state v0.0.2

Weekly downloads
54
License
-
Repository
github
Last release
4 years ago

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],
    );
    // ...
}